KEDA Tutorial: Event-Driven Autoscaling on Kubernetes

KEDA scales Kubernetes workloads on real events - queue depth, Kafka lag, HTTP traffic, even a cron schedule - and can scale all the way to zero. Here is how it works and how to set it up.

#kubernetes#autoscaling#keda

What is KEDA?

KEDA (Kubernetes Event-Driven Autoscaling) is a CNCF project that scales your Kubernetes workloads based on the events that actually drive load - the number of messages in a queue, consumer lag on a Kafka topic, the result of a Prometheus query, or even the time of day - rather than only CPU and memory.

Crucially, KEDA can scale to zero: when there is no work to do, your deployment drops to zero replicas and costs you nothing, then spins back up the moment events arrive.

How KEDA works

KEDA does not replace the Horizontal Pod Autoscaler - it drives one. You install KEDA into your cluster, then describe what to scale on with a ScaledObject:

KEDA = HPA + event sources

Everything the HPA does still applies. KEDA just gives it metrics the HPA could never see on its own, and adds the zero-to-one transition.

Installing KEDA

The simplest path is the official Helm chart:

helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm install keda kedacore/keda --namespace keda --create-namespace

Verify the operator is running:

kubectl get pods -n keda

Scaling a deployment on queue depth

Here is a ScaledObject that scales a worker deployment based on the number of messages in a RabbitMQ queue - one replica per 20 messages, up to 30 replicas:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: worker-scaler
spec:
  scaleTargetRef:
    name: worker
  minReplicaCount: 0
  maxReplicaCount: 30
  triggers:
    - type: rabbitmq
      metadata:
        host: amqp://guest:guest@rabbitmq.default.svc:5672/
        queueName: jobs
        mode: QueueLength
        value: "20"

Apply it and KEDA takes over scaling:

kubectl apply -f worker-scaler.yaml
kubectl get scaledobject

Scaling to zero

Because minReplicaCount is 0, when the jobs queue empties KEDA scales worker down to zero pods. The instant a message lands, KEDA activates the deployment back to one replica, and the HPA takes it from there based on queue depth. This is the headline feature: idle workloads cost nothing.

When to use KEDA

KEDA shines for event-driven and bursty workloads:

For steady, CPU-bound web services, the plain HPA is often enough - reach for KEDA when load is driven by an external signal the HPA cannot measure.

Frequently asked questions

What is KEDA?

KEDA (Kubernetes Event-Driven Autoscaling) is a CNCF project that scales Kubernetes workloads based on external event sources - like queue length, Kafka consumer lag, or a Prometheus query - instead of only CPU and memory. It can also scale a deployment to zero when there is no work.

How is KEDA different from the Horizontal Pod Autoscaler (HPA)?

The built-in HPA scales on CPU/memory. KEDA extends it: under the hood it creates and manages an HPA, but feeds it custom event-based metrics (queue depth, Kafka lag, and so on) through components called scalers, and it uniquely supports scaling to zero. Think of KEDA as HPA plus event sources.

Can KEDA scale to zero?

Yes. When the event source reports no work - for example an empty queue - KEDA can scale the deployment down to zero replicas, then scale it back up when events arrive. A standard HPA cannot go below one replica.

What event sources does KEDA support?

KEDA ships 60+ scalers, including Kafka, RabbitMQ, AWS SQS, Azure Service Bus, Google Pub/Sub, Prometheus, Redis, PostgreSQL, and cron schedules.

Practice on a live Kubernetes workspace. Reading is step one. Now fix a real Kubernetes system in a live cloud workspace - and every fix lands on a portfolio hiring managers can open.

Start free →