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.
FeatureHPA aloneKEDA
SignalsCPU, memory, custom metrics you provideDozens of event sources
To zeroBeta in v1.37, Object or External metric onlyYes (min 0)
JobsNoScaledJob
TypeBuilt inAdd-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.
Event sourceKafka / SQS/ Prometheus polls30s Scalerin keda-operator value metrics-apiserverexternal metrics active? metrics keda-operator HPA 0 to 1 1 to N Deployment Pods (0..N) two tracks,one Deployment
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.

ScaledObject authenticationRef TriggerAuthentication secretTargetRef Secret / pod identity Scaler with creds Event source reads thecredentials
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.

KindScopePurpose
ScaledObjectNamespacedScale a workload on triggers
ScaledJobNamespacedSpawn Jobs per event
TriggerAuthenticationNamespacedCredentials for a scaler
ClusterTriggerAuthenticationClusterShared 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

CommandDescriptionExample
helm repo add kedacore https://kedacore.github.io/chartsAdd the official chart repohelm repo update
helm install keda kedacore/keda -n keda --create-namespaceInstall KEDA via Helmkubectl apply --server-side -f keda-2.21.0.yaml
kubectl get pods -n kedaVerify operator, metrics server, webhookskubectl get pods -n keda -w
kubectl get scaledobject -AList ScaledObjects, READY / ACTIVEkubectl get so -n prod
kubectl describe scaledobject NAMEConditions and events when nothing scaleskubectl describe scaledobject worker-scaler
kubectl get hpaKEDA-made HPA, named keda-hpa-NAMEkubectl get hpa keda-hpa-worker-scaler
kubectl annotate scaledobject NAME autoscaling.keda.sh/paused=truePause at current replicas. KEDA deletes its HPA until the annotation goeskubectl annotate scaledobject worker-scaler autoscaling.keda.sh/paused-replicas=0
kubectl logs -n keda deploy/keda-operatorScaler errors (auth, connection)kubectl logs -n keda deploy/keda-operator --tail=50
kubectl get apiservice v1beta1.external.metrics.k8s.ioIs the external metrics API Available ?kubectl get --raw /apis/external.metrics.k8s.io/v1beta1
helm uninstall keda -n kedaRemove KEDA. Delete its objects first, while it runs, or they hang on finalizer.keda.shkubectl 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.