Q: Your message processing microservice on AKS consumes orders from Azure Service Bus. During flash sales, 500,000 messages flood the queue in 2 minutes. Standard Horizontal Pod Autoscaler (HPA) based on CPU/memory scales too slowly, causing huge message processing lag. How do you implement KEDA with Azure Service Bus and Cluster Autoscaler to scale pods from 0 to 300 instances dynamically?
Engineering a responsive event-driven autoscaling pipeline on AKS using Kubernetes Event-driven Autoscaling (KEDA) triggered by Azure Service Bus queue depths and synchronized with Cluster Autoscaler.
Want to master this scenario in a live sandbox? Stephane Maarek's AWS Certified DevOps Engineer Professional Masterclass on Udemy covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Enable KEDA Add-on on Azure Kubernetes Service
Activate the managed KEDA controller directly via Azure CLI:
- Enable Add-on: Executed
az aks update --resource-group rg-aks --name aks-prod --enable-keda. - Verify KEDA Operator: Confirmed
keda-operatorandkeda-metrics-apiserverpods are running in thekube-systemnamespace.
Configure KEDA TriggerAuthentication with Azure Workload Identity
Securely authenticate KEDA against Azure Service Bus without storing connection strings:
- TriggerAuthentication CRD: Created
TriggerAuthenticationreferencing pod Workload Identity withidentityId: $MANAGED_IDENTITY_CLIENT_ID. - Azure RBAC: Granted the Managed Identity
Azure Service Bus Data ReceiverandAzure Service Bus Data Ownerroles on the Service Bus namespace.
Deploy KEDA ScaledObject with Scaled Metric Targets
Define the scaling rules binding the deployment to queue message depth:
- ScaledObject Manifest: Applied
ScaledObjecttargetingorder-processordeployment withminReplicaCount: 0,maxReplicaCount: 300, andcooldownPeriod: 300. - Trigger Spec: Configured
azure-servicebustrigger withqueueName: ordersandmessageCount: 50(spawning 1 pod for every 50 pending messages).
Tune AKS Cluster Autoscaler for Rapid Scale-Out
Prevent pod scheduling bottlenecks when hundreds of pods are created simultaneously:
- Autoscaler Profile: Configured cluster autoscaler profile:
az aks update -g rg-aks -n aks-prod --cluster-autoscaler-profile scan-interval=10s,scale-down-delay-after-add=10m,scale-down-unneeded-time=5m. - Overprovisioning Buffer: Deployed a low-priority pause pod deployment to reserve spare node capacity, ensuring immediate scheduling of incoming worker pods while new nodes boot.
- Enable the managed KEDA add-on on AKS via Azure CLI.
- Authenticate KEDA securely against Azure Service Bus using Azure AD Workload Identity.
- Deploy ScaledObject CRDs to scale pods from 0 to 300 based on exact message queue depth.
- Tune Cluster Autoscaler scan intervals and deploy pause pod overprovisioning for instant pod scheduling.