Skip to content

Reference Implementation about KEDA supporting MySql and Azure Service Bus scalers

License

Notifications You must be signed in to change notification settings

oaviles/keda-example

 
 

Repository files navigation

DevSquad KEDA Project

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.

Setup up your repo

Create AKS Cluster

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 KEDA Demo

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.

Observe

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"

MySQL example

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

Azure Service Bus Sample

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:
  • 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.

About

Reference Implementation about KEDA supporting MySql and Azure Service Bus scalers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 83.9%
  • Bicep 11.7%
  • Dockerfile 3.5%
  • Shell 0.9%