KEDA Event-Driven Pod Autoscaling Guide
Scale Kubernetes workloads on external events with KEDA. Covers Kafka queue length, Prometheus metrics, and cron schedule trigger patterns.
π‘ Quick Answer: Install KEDA and create
ScaledObjectresources that define custom scaling triggers. Scale on Kafka consumer lag, Prometheus query results, cron schedules, or any of 60+ supported scalers. KEDA enables true scale-to-zero β 0 pods when no events, instant scale-up on first event.
The Problem
HPA scales on CPU and memory β but event-driven workloads need to scale on queue depth, message backlog, or scheduled patterns. A Kafka consumer sitting at 5% CPU shouldnβt scale down if 10,000 messages are waiting in the topic. KEDA bridges this gap with event-source-aware autoscaling.
The Solution
Install KEDA
helm repo add kedacore https://kedacore.github.io/charts
helm install keda kedacore/keda --namespace keda --create-namespaceScale on Kafka Consumer Lag
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: kafka-consumer
namespace: production
spec:
scaleTargetRef:
name: order-processor
pollingInterval: 15
cooldownPeriod: 300
minReplicaCount: 0
maxReplicaCount: 20
triggers:
- type: kafka
metadata:
bootstrapServers: kafka.messaging:9092
consumerGroup: order-group
topic: orders
lagThreshold: "100"Scale on Prometheus Metric
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: api-scaler
spec:
scaleTargetRef:
name: api-server
minReplicaCount: 2
maxReplicaCount: 50
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus.monitoring:9090
query: sum(rate(http_requests_total{service="api"}[2m]))
threshold: "100"Cron-Based Scaling
triggers:
- type: cron
metadata:
timezone: America/New_York
start: "0 8 * * 1-5"
end: "0 18 * * 1-5"
desiredReplicas: "10"Scale to 10 replicas during business hours, scale down after hours.
graph TD
KAFKA[Kafka Topic<br/>10K messages waiting] -->|Consumer lag > 100| KEDA[KEDA]
PROM[Prometheus<br/>100 req/s] -->|Threshold exceeded| KEDA
CRON[Cron<br/>Business hours] -->|Schedule| KEDA
KEDA -->|Scale 0β20| DEPLOY[Deployment<br/>order-processor]
KEDA -->|Scale to 0<br/>when idle| ZERO[0 replicas π€]Common Issues
Pods not scaling to zero: minReplicaCount: 0 must be set AND the trigger must report 0. Check: kubectl get scaledobject -o yaml for trigger status.
Scaling too slow: Reduce pollingInterval from 30s to 10s. For Kafka, ensure the consumer group is active β inactive groups donβt report lag.
Best Practices
- Scale-to-zero for cost savings β 0 pods when no events to process
- Kafka lag threshold β tune based on processing time per message
- Combine triggers β Kafka lag + cron for pre-scaling before peak hours
cooldownPeriod: 300β prevent rapid scale-down oscillation- 60+ scalers available β AWS SQS, RabbitMQ, Redis, HTTP, Prometheus, cron
Key Takeaways
- KEDA enables event-driven autoscaling with 60+ supported scalers
- True scale-to-zero β 0 replicas when no events, instant scale-up on first event
- Scale on Kafka lag, Prometheus metrics, cron schedules, and more
- Complements HPA β KEDA handles the event sources, HPA handles the scaling mechanics
- Essential for event-driven architectures: message queues, batch processing, scheduled jobs

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses βπ Deepen Your Skills β Hands-on Courses
Courses by CopyPasteLearn.com β Learn IT by Doing
