Reference Architecture: The diagram below shows how KEDA integrates with the Kubernetes HPA, external event sources, and Kubernetes’ API Server to provide autoscaling functionality.
This repository consists of everything you need to setup simple Kubernetes cluster and demonstrate usage of KEDA mysql scalers. For more samples check https://github.com/kedacore/samples
The included helper
provides an easy way to perform both 0 -> n and n -> 0 scalings.
- Import or fork this repo in your GitHub Account. How to import a repo
- Create the necesary secrets in your repo. How to create secrets and Set up Secrets in GitHub Action workflows
- You can refer this repo to create your AKS Cluster: DevSquad Cloud-Native Project
- Run GitHub Action called "Deploy AKS"
- In this repo, run GitHub Action called "Setup Keda"
- Optional: Manual deployment: Follow the official KEDA guide https://keda.sh/deploy/ (Note: This step is required if you do not execute the previous step)
The deployment consists of 4 components: In this repo, run GitHub Action called "Deploy Keda Demo"
- MySQL instance
- Dummy pod that will be scaled up and down
- App service that provides some helper methods
- Optional: Update and run GitHub Action called "Build and Push image to Docker Hub" to push images in your own Docker Account or Private Docker Registry like Azure Container Registry.
To observe how everything works you can watch two things:
- Number of pods and their state:
watch -n2 "kubectl get pods"
- HPA stats:
watch -n2 "kubectl get hpa"
To scale the dummy deployment using
MySQL scaler first we have to
deploy the ScaledObjects
:
kubectl apply -f keda/mysql-hpa.yaml
this should result again in creation of ScaleObject
and an HPA:
# kubectl get scaledobjects
NAME DEPLOYMENT TRIGGERS AGE
mysql-scaledobject dummy mysql 5s
# kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
keda-hpa-dummy Deployment/dummy <unknown>/5 (avg) 1 4 0 45s
To scale up we have to insert some values to MySQL database. To do this we can use the helper app:
kubectl exec $(kubectl get pods | grep "server" | cut -f 1 -d " ") -- keda-talk mysql insert
and to scale down:
kubectl exec $(kubectl get pods | grep "server" | cut -f 1 -d " ") -- keda-talk mysql delete
Reference guide: .NET Core worker processing Azure Service Bus Queue scaled by KEDA, or in this repo you can reuse YAML files on "sevicebus" folder.
- Create AKS Cluster:
- You can refer this repo to create your AKS Cluster: DevSquad Cloud-Native Project
- Setup Secrets defined in GitHub Action called "Deploy AKS"
- Run GitHub Action called "Deploy AKS"
- Setup Secrets defined in GitHub Action called "Depoy Azure Service Bus (Bicep)"
- Install KEDA:
- In this repo, run GitHub Action called "Setup Keda"
- Optional: Manual deployment: Follow the official KEDA guide https://keda.sh/deploy/ (Note: This step is required if you do not execute the previous step)
- Deploy Azure Service Bus using GitHub Action called "Depoy Azure Service Bus (Bicep)"
- Get Connestion String from Azure Service Bus Queue "Orders"
- Encode Connection String with this command
echo -n < your connection string here > | base64
- Update YAML files "deploy-app.yaml" and "deploy-autoscaling.yaml" with the encoded connection string in the text < base64-encoded-connection-string >
- Update YAML files "deploy-app.yaml" and "deploy-autoscaling.yaml" with the queue name "orders" in the text < your-queue >
- Options to send messages to Azure Service Bus:
- Option 1: Console App to sent messages to the queue called "orders", you can reuse the client application in this repo "OrderGenerator". To run the project, use the command "dotnet run --project", example
dotnet run --project Keda.Samples.Dotnet.OrderGenerator.csproj
- Option 2: Serverless App (Azure Function App) to send message to the queue called "order", you can reuse the project from here.
- Option 1: Console App to sent messages to the queue called "orders", you can reuse the client application in this repo "OrderGenerator". To run the project, use the command "dotnet run --project", example