Scaling and metrics
KEDA
1.What is KEDA ?
KEDA scales your workloads based on external events (queue length, Kafka lag, cron, Prometheus query) and can shrink them to zero pods when idle.
- Built-in HPA only scales on CPU / memory.
- A backlog of 10k messages can sit at low CPU.
- An HPA reaches zero only with an Object or External metric (beta in v1.37). Idle workers burn money.
- KEDA ships many ready-made scalers.
- Batch work wants one Job per event.
- Pay for workers only while there is work to do.
| Feature | HPA alone | KEDA |
|---|---|---|
| Signals | CPU, memory, custom metrics you provide | Dozens of event sources |
| To zero | Beta in v1.37, Object or External metric only | Yes (min 0) |
| Jobs | No | ScaledJob |
| Type | Built in | Add-on that feeds an HPA |
HistoryMade by Microsoft and Red Hat (2019). CNCF accepted 2020, incubating 2021, graduated 2023-08-22. Latest v2.21.0 (2026-09-23); a 2.21.1 patch is agreed, not out yet.
2.How KEDA scales
KEDA does not replace HPA, it drives it. Two tracks :
- 0 1 is done by keda-operator.
- 1 N is done by a normal HPA fed by KEDA metrics.
Activation vs scalingactivationThreshold gates 0 1. threshold sets the target per pod for 1 N. Activation fires only when the value is strictly greater.
Scale targetDeployment, StatefulSet or any resource with a /scale subresource.
3.Components
- keda-operatorWatches ScaledObject / ScaledJob, creates the HPA, does 0 1.
- metrics-apiserverServes external.metrics.k8s.io so the HPA can read event metrics.
- admission-webhooksValidate KEDA resources on apply (not in the -core manifest).
- ScalersBuilt-in plugins that query an event source.
- HPA (generated)Created per ScaledObject, does 1 N.
- HTTP Add-onOptional, separate, beta. Scales on HTTP traffic.
Where things liveKEDA itself lives in the keda namespace. A ScaledObject lives beside the workload it scales.
operator, metrics server, webhooks
Key PointsInstall with Helm into the keda namespace. One ScaledObject per workload. Pick the HPA by name if you already have one.
In short : KEDA watches events, the operator handles 0 1, and a generated HPA handles 1 N.
1.ScaledObject
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: worker-scaler
spec:
scaleTargetRef:
name: worker
minReplicaCount: 0
maxReplicaCount: 20
pollingInterval: 30
cooldownPeriod: 300
triggers:
- type: rabbitmq
metadata:
queueName: tasks
mode: QueueLength
value: "10" # ~10 msgs per pod
authenticationRef:
name: rabbit-auth
2.Authentication
Credentials live in TriggerAuthentication (namespaced) or ClusterTriggerAuthentication (shared), referencing Secrets or pod identity.
Key fieldsscaleTargetRef picks the workload. triggers[] holds one or more event sources. authenticationRef points at the credentials.
ScaledObject defaultspollingInterval 30s, cooldownPeriod 300s, min 0, max 100. Since 2.21, with min above 0 and no idle count, cached metrics or modifiers, KEDA reuses the HPA's own reads: pollingInterval then paces only status.
3.ScaledObject vs ScaledJob
Queue event
ScaledObjectscales existing Deployment
Queue event
ScaledJobnew Job per event, runs to completion
Use ScaledJob for long-running or one-shot tasks.
| Kind | Scope | Purpose |
|---|---|---|
| ScaledObject | Namespaced | Scale a workload on triggers |
| ScaledJob | Namespaced | Spawn Jobs per event |
| TriggerAuthentication | Namespaced | Credentials for a scaler |
| ClusterTriggerAuthentication | Cluster | Shared credentials |
In short : A ScaledObject points KEDA at a workload and its triggers, a TriggerAuthentication holds the credentials, and a ScaledJob spawns a new Job per event instead.
1.Commands
| Command | Description | Example |
|---|---|---|
| helm repo add kedacore https://kedacore.github.io/charts | Add the official chart repo | helm repo update |
| helm install keda kedacore/keda -n keda --create-namespace | Install KEDA via Helm | kubectl apply --server-side -f keda-2.21.0.yaml |
| kubectl get pods -n keda | Verify operator, metrics server, webhooks | kubectl get pods -n keda -w |
| kubectl get scaledobject -A | List ScaledObjects, READY / ACTIVE | kubectl get so -n prod |
| kubectl describe scaledobject NAME | Conditions and events when nothing scales | kubectl describe scaledobject worker-scaler |
| kubectl get hpa | KEDA-made HPA, named keda-hpa-NAME | kubectl get hpa keda-hpa-worker-scaler |
| kubectl annotate scaledobject NAME autoscaling.keda.sh/paused=true | Pause at current replicas. KEDA deletes its HPA until the annotation goes | kubectl annotate scaledobject worker-scaler autoscaling.keda.sh/paused-replicas=0 |
| kubectl logs -n keda deploy/keda-operator | Scaler errors (auth, connection) | kubectl logs -n keda deploy/keda-operator --tail=50 |
| kubectl get apiservice v1beta1.external.metrics.k8s.io | Is the external metrics API Available ? | kubectl get --raw /apis/external.metrics.k8s.io/v1beta1 |
| helm uninstall keda -n keda | Remove KEDA. Delete its objects first, while it runs, or they hang on finalizer.keda.sh | kubectl delete scaledobjects,scaledjobs --all -A |
2.When nothing scales
get scaledobjectREADY / ACTIVE ?
describeconditions and events
keda-operator logsscaler errors (auth, connection)
get apiserviceexternal metrics API Available ?
get hpakeda-hpa-NAME
3.Gotchas & Good to know
Gotchas
- No second HPA on a scaled Deployment. The webhook refuses a ScaledObject over an existing HPA; a plain HPA made after it is admitted, then both stall with AmbiguousSelector.
- Activation is strictly greater : threshold 10, activation 50, metric 40 stays at zero.
- Scale to zero waits cooldownPeriod (300s) after the last active poll, then goes straight from any count to 0, past the HPA's scale-down window.
- Scale-down can kill pods mid-task. Handle SIGTERM or use ScaledJob.
Good to know
- Several triggers can be combined with scaling modifiers.
- HTTP scaling is the separate HTTP Add-on (beta), or use Prometheus request rate.
- v2.21.0 breaks three things : a boundServiceAccountToken needs its audience mapped in the operator's settings, not the TriggerAuthentication (CVE-2026-77524); azure-pipelines scaleOnInFlight is now true; Temporal loses buildId, selectAllActive and selectUnversioned.
- A bad TriggerAuthentication shows only as not READY with the source's own error (Redis : NOAUTH). A missing one is only logged; a missing Secret key is not logged at all.
In short : Install with Helm, check READY / ACTIVE on the ScaledObject, and never give the same Deployment a second HPA.