What is KEDA? Event-driven autoscaling on Kubernetes
Learn how KEDA scales workloads based on queues, metrics, and schedules — all the way down to zero — with ScaledObject examples for RabbitMQ, Prometheus, and cron, the key settings, and production pitfalls.
Kubernetes$ kubectl get scaledobjects -A▍A queue piles up 50,000 messages at 3 a.m. The workers sit at 15% CPU — after all, they spend most of their time waiting on I/O — and the HPA concludes everything is fine. Meanwhile, orders are delayed. The problem isn’t autoscaling; it’s the signal used to scale. KEDA exists to swap that signal for what actually matters: queue length, request rate, time of day.
Why CPU-based HPA isn’t enough
The native Horizontal Pod Autoscaler scales well on CPU and memory, but those numbers are an indirect reflection of demand. In event-driven workloads:
- a queue consumer can be idle on CPU while thousands of messages wait;
- the HPA doesn’t scale to zero replicas by default — something is always running, even with no work;
- using external metrics in the HPA requires a metrics adapter and manual configuration for every source.
How KEDA works
KEDA (Kubernetes Event-driven Autoscaling) is a CNCF graduated project that extends the HPA instead of replacing it. It runs as an operator with three pieces:
- Operator (keda-operator): watches KEDA resources, queries event sources through scalers, and handles activation: it takes the workload from 0 to 1 replica when work shows up and back to 0 when it’s done.
- Metrics server (keda-operator-metrics-apiserver): exposes scaler values through the Kubernetes external metrics API.
- Admission webhooks: validate resources, preventing, for example, two ScaledObjects on the same Deployment.
The division of labor is the key: from 0 to 1 (and from 1 to 0), KEDA decides; from 1 to N, the HPA decides, and KEDA itself creates that HPA and feeds it the metrics. There are dozens of ready-made scalers — RabbitMQ, Kafka, AWS SQS, Azure Service Bus, Redis, PostgreSQL, Prometheus, cron, and many more.
Installation
The recommended route is the official chart (if you need an introduction, see what is Helm):
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm install keda kedacore/keda --namespace keda --create-namespace
kubectl get pods -n keda
kubectl get crd | grep keda.sh
KEDA resources
They all live in the keda.sh/v1alpha1 group:
- ScaledObject: scales a Deployment, StatefulSet, or custom resource with a
scalesubresource. It’s the most common case: long-running workers. - ScaledJob: instead of scaling replicas, it creates Kubernetes Jobs according to event volume. Ideal for long tasks, where killing a pod mid-processing would be expensive.
- TriggerAuthentication / ClusterTriggerAuthentication: keep credentials separate from triggers, reading them from Secrets, environment variables, or the cloud provider’s workload identities.
Practical examples
RabbitMQ queue
A worker that processes orders, scaling from 0 to 30 replicas based on the queue:
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: rabbitmq-auth
namespace: orders
spec:
secretTargetRef:
- parameter: host # amqp://... URL stored in the Secret
name: rabbitmq-conn
key: host
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: orders-worker
namespace: orders
spec:
scaleTargetRef:
name: orders-worker # target Deployment
minReplicaCount: 0
maxReplicaCount: 30
pollingInterval: 15
cooldownPeriod: 300
triggers:
- type: rabbitmq
metadata:
protocol: amqp
queueName: orders
mode: QueueLength
value: "50" # target of ~50 messages per replica
authenticationRef:
name: rabbitmq-auth
After applying it, check with kubectl get scaledobject -n orders and kubectl get hpa -n orders — KEDA creates an HPA named keda-hpa-orders-worker. For AWS SQS, the aws-sqs-queue trigger follows the same idea, with queueURL, queueLength, and awsRegion.
Prometheus metric
Scale an API by request rate instead of CPU:
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus-operated.observability.svc:9090
query: sum(rate(http_requests_total{service="checkout"}[2m]))
threshold: "100" # ~100 req/s per replica
activationThreshold: "5" # below this, it can go to zero
Cron schedule
Guarantee capacity during business hours, before the peak arrives:
triggers:
- type: cron
metadata:
timezone: America/New_York
start: 0 8 * * 1-5
end: 0 20 * * 1-5
desiredReplicas: "10"
Triggers can be combined in the same ScaledObject: the HPA computes replicas for each metric and uses the highest value. A baseline cron plus a queue trigger is a common combination.
Key settings
| Field | Default | What it does |
|---|---|---|
pollingInterval |
30 s | How often KEDA queries each trigger |
cooldownPeriod |
300 s | Wait after the last event before going back to zero (doesn’t affect N→1) |
minReplicaCount |
0 | Minimum replicas; 0 enables scale to zero |
maxReplicaCount |
100 | Replica ceiling passed on to the HPA |
fallback |
— | Replicas to keep if the scaler keeps failing |
advanced.horizontalPodAutoscalerConfig |
— | Tunes the HPA behavior (scale-up and scale-down speed) |
Common pitfalls
- Cold starts: coming from zero, the first message waits for polling, pod scheduling, the image pull, and application startup. If latency matters, use
minReplicaCount: 1. - Source limits: 30 replicas with 10 connections each means 300 connections to the database or broker. Size
maxReplicaCountby what the downstream can handle — and remember that polling itself also queries the source. - Node capacity: KEDA creates pods, not machines. Without Cluster Autoscaler or Karpenter, new replicas stay
Pending. See how Karpenter provisions nodes on demand in FinOps for AI. - Idempotent consumers: on scale-down, pods are terminated mid-work. Handle
SIGTERM, acknowledge a message only after processing it, and accept redeliveries. For long tasks, preferScaledJob. - Conflicts: don’t create your own HPA for the same Deployment; in GitOps, omit
replicasfrom the manifest so Argo CD or Flux don’t fight the autoscaler. And the cluster accepts a single external metrics provider — KEDA can conflict with another adapter that also serves them.
To understand how the HPA, the scheduler, and the kubelet fit into this flow, see how Kubernetes works.
FinOps: pay only for what you process
Scale to zero is where KEDA turns into real savings. Workers in development environments, queues that only receive batch messages at night, and consumers of rare events can spend most of their time at zero replicas. Combined with a node autoscaler, idle nodes disappear too — and the bill drops with them. It’s the opposite of zombie cloud resources: capacity that exists only while there’s work. More strategies in FinOps to cut AWS costs.
Checklist
- Pick the signal that represents real demand (queue, rate, schedule), not just CPU
- Install KEDA via Helm and keep credentials in a
TriggerAuthentication - Set
minReplicaCountwith the cost of cold starts in mind - Cap
maxReplicaCountby what the broker or database can handle - Ensure node capacity with Cluster Autoscaler or Karpenter
- Make consumers idempotent and handle
SIGTERM - Remove
replicasfrom manifests managed by GitOps
The best autoscaler isn’t the fastest one — it’s the one that scales for the right reason and knows when to turn everything off.