Skip to main content
Running workloadsLesson 10 of 14

Scaling on Events with KEDA

A queue consumer can sit at low CPU while thousands of messages wait. Follow KEDA as it reads the backlog, drives an HPA, scales to zero and back, and decides what to do when it cannot reach the queue.

Lag / backlog5,000
Replicas2
KEDA—
Kubernetes clusterKafka topicorders · lagQueuee.g. RabbitMQ, SQSPrometheusPromQL queryScaledObjecttriggers · min · maxTriggerAuthSecret refsScaledJobJob templateKEDA operatorPolls triggers · 0↔1Metrics serverExternal metrics APIHPAkeda-hpa-orders · 1↔NDeploymentorders consumerJobsOne per message
RequestWatchAppears in a later step

What you will learn

  • Why CPU misses queue backlog
  • ScaledObject triggers and the HPA KEDA creates for you
  • Activation (0↔1) versus scaling (1↔N) thresholds
  • Scale to zero, cold start and cooldownPeriod
  • Secrets with TriggerAuthentication, one Job per message with ScaledJob
  • Fallback when the metric source is down

ScaledObject fields that change behavior​

FieldDefaultWhat it controls
minReplicaCount0Lowest replica count. Above 0, the activation threshold is ignored
maxReplicaCount100Highest replica count passed to the HPA
pollingInterval30 sHow often the operator checks each trigger
cooldownPeriod300 sWait after the last active trigger before going to 0. Only for 1 → 0
initialCooldownPeriod0 sWait after creation before the first scale to 0
idleReplicaCountunsetReplicas when no trigger is active (only 0 is supported, and it must be below minReplicaCount)
fallback.failureThreshold / fallback.replicasnoneAfter this many failed polls, scale to this count
advanced.horizontalPodAutoscalerConfig.behaviorHPA defaultsScale-up and scale-down speed for 1 ↔ N
trigger activation… (e.g. activationLagThreshold)0Metric must be above this to wake from 0

Try it yourself​

kubectl get scaledobject -A # READY, ACTIVE, FALLBACK, TRIGGERS
kubectl describe scaledobject orders # Conditions and events from the operator
kubectl get hpa keda-hpa-orders # The HPA KEDA created
kubectl describe hpa keda-hpa-orders # Current external metric value and scaling events
kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1" | head -c 400 # KEDA metrics server is registered
kubectl get triggerauthentication,clustertriggerauthentication -A
kubectl get scaledjob,jobs -A # ScaledJob and the Jobs it created
kubectl logs -n keda deploy/keda-operator | tail # Scaler errors (adjust namespace to your install)

Check yourself

  1. A ScaledObject has minReplicaCount 0, cooldownPeriod 300 and an HPA scale-down window of 300 seconds. Load falls from 10 replicas to none. Which part decides the drop from 10 to 1?
  2. A consumer scaled to zero. A single message arrives every 10 minutes at night, and a Pod keeps starting and stopping. What fixes this most directly?
  3. The Prometheus server behind a trigger goes down and no fallback is set. What happens to replicas?

Further reading: KEDA concepts · ScaledObject spec · Scaling Jobs · Kafka scaler · Authentication · Scaling with Load (HPA) · Autoscaling LLM Inference · Run Once and Finish (Job · CronJob)