KEDA

KEDA (Kubernetes Event-driven Autoscaling) is an open-source component that scales Kubernetes workloads based on external events, such as queue length or stream lag, including scaling down to zero.

Also known as: Kubernetes Event-driven Autoscaling

Related terms in this glossary

How it works

The standard Horizontal Pod Autoscaler scales on CPU, memory or metrics you expose yourself. KEDA adds a large catalog of scalers that read event sources directly, such as Kafka consumer lag, RabbitMQ or Amazon SQS queue depth, Azure Service Bus, Redis lists, Prometheus queries, database queries and cron schedules.

  • You create a ScaledObject that points to a Deployment or StatefulSet and lists triggers and thresholds.
  • KEDA acts as a metrics adapter and creates and manages an HPA for that workload, so scaling above one replica still uses standard Kubernetes behavior.
  • KEDA itself handles activation: moving from zero to one replica when events arrive, and back to zero when idle.
  • A ScaledJob runs a Kubernetes Job per batch of events, useful for long-running tasks.

KEDA was started by Microsoft and Red Hat, and it graduated from the CNCF in August 2023.

Why it matters

Many workloads are driven by queues or streams, not by CPU. Scaling on the backlog reacts before CPU rises and matches capacity to real work. Scale to zero means idle consumers, preview environments or batch workers cost nothing between jobs. KEDA pairs well with a node autoscaler such as Karpenter, which removes the empty nodes. Things to plan for are cold-start time when scaling from zero and secure credentials for the event sources. See Gepton's Kubernetes service.

KEDA in depth

Example: scaling invoice workers on a queue

Example: a hypothetical company processes uploaded invoices through a queue in RabbitMQ. Workers run as a Deployment. A ScaledObject targets that Deployment with a RabbitMQ trigger based on queue length per replica, with minReplicaCount of zero and a sensible maxReplicaCount that the downstream database can handle. Credentials come from a TriggerAuthentication that references a Kubernetes Secret populated by the External Secrets Operator. When invoices arrive in the morning, KEDA activates the Deployment from zero to one replica and the HPA it manages scales further based on backlog. In the evening the queue empties, and after the cooldown period KEDA scales the workers back to zero. Karpenter then removes the nodes that became empty.

Key settings to understand

  • pollingInterval: how often KEDA checks each trigger; shorter means faster activation but more load on the event source.
  • cooldownPeriod: how long to wait after the last activity before scaling to zero; it applies only to the zero step, while scaling between one and the maximum follows HPA behavior.
  • minReplicaCount and maxReplicaCount: bounds for the workload, with zero allowed as a minimum.
  • fallback: a replica count to use if the scaler cannot read its metric, so an outage of the metrics source does not scale the workload down.
  • advanced HPA behavior: pass-through settings for scale-up and scale-down policies on the generated HPA.
  • Pausing: an annotation pauses autoscaling during maintenance or incidents.

ScaledObject or ScaledJob

ResourceBest forBehavior
ScaledObjectLong-running consumers and servicesScales replicas of a Deployment, StatefulSet or custom resource
ScaledJobLong or uneven tasks such as video processing or report generationCreates Kubernetes Jobs for pending work, so a scale-down never kills a task midway

Security and operations

Prefer workload identity over static secrets where supported: TriggerAuthentication can use pod identity providers for AWS, Azure and Google Cloud. Give scaler credentials read-only access to queue metrics, not permission to consume or delete messages. Monitor KEDA's own metrics and the generated HPA's events, and alert when a scaler reports errors, since a broken scaler silently stops scaling.

How to evaluate KEDA autoscaling

  • Backlog age: how long the oldest message waits, the measure users actually feel.
  • Activation delay from first event to first processed item, including cold start.
  • Replica count over time against queue depth, to spot lag or flapping.
  • Idle capacity and compute spend during quiet hours.

Common mistakes

  • Creating a separate HPA for a workload that KEDA already manages, causing the two to conflict.
  • Scaling to zero for latency-sensitive services where a cold start is unacceptable; keep a minimum of one, or look at the KEDA HTTP add-on with care.
  • Maximum replicas higher than a downstream database or API can handle.
  • Thresholds set without load testing.

KEDA extends the Horizontal Pod Autoscaler, pairs with node autoscalers, and supports FinOps goals on Kubernetes. It also suits AI pipelines such as document processing or batch inference workers. We set it up in our Kubernetes and cloud cost optimization and FinOps services.

Questions about KEDA

Something else? Send us your question and an engineer replies with next steps.

Can KEDA scale workloads based on a Prometheus query?

Yes. KEDA's Prometheus scaler runs a query you define against your Prometheus server and scales the workload so that the query result per replica stays near a threshold. This is useful for metrics that are already collected, such as requests per second, pending jobs recorded by the application or business events. Make sure the query is efficient, returns a single value and behaves sensibly when data is missing, and configure a fallback replica count in case Prometheus is unavailable.

Does KEDA work with Kafka consumer groups?

Yes. The Kafka scaler reads consumer group lag, meaning how many messages are waiting to be processed, and scales the consumer workload to keep lag per replica near your threshold. One important limit: Kafka assigns each partition to at most one consumer in a group, so replicas beyond the number of partitions sit idle. Set maxReplicaCount with your partition count in mind, and plan partition numbers when designing topics that need to scale out.

Articles that mention KEDA

All articles

Jump to

↑↓ to move↵ to open