Kubernetes autoscaling: HPA, VPA, KEDA and nodes
The four ways a cluster grows and shrinks, and how they work together without fighting.
The Horizontal Pod Autoscaler (HPA) changes the number of replicas to keep a metric near a target, usually CPU as a percentage of requests. It reads metrics-server, checks every 15 seconds, scales up quickly and down slowly. Without CPU requests set, it can't work out a percentage.
The Vertical Pod Autoscaler (VPA) recommends or sets requests and limits from real use. KEDA scales on events, such as messages waiting in a queue, and can scale to zero. The cluster autoscaler (or Karpenter, or AKS node auto-provisioning) adds nodes when pods are Pending for lack of room and removes empty ones.
They work as a chain: HPA or KEDA adds pods, the scheduler places them, and if there's no room the node autoscaler adds a node. Don't let HPA and VPA both control CPU for the same app: they fight.
Cost. Free to learn on kind (for pod scaling). Node scaling costs money in a cloud: you pay for every node it adds.
Use it when
- load changes through the day or week.
- work arrives in queues.
- you're paying for idle nodes at night.
How it works
- HPA
- Replicas follow a metric target; needs requests and metrics.
- VPA
- Right-sizes requests from history; often used in recommend mode.
- KEDA
- Event-driven scaling, including to zero.
- Node autoscaling
- Adds and removes nodes to fit pending pods.
Options
- CPU target
- Simple and common; fine for web APIs.
- Queue length
- Better for workers; use KEDA.
- Schedule
- Known peaks; scale ahead of time.
Example. Tollmere Logistics' tracking API uses an HPA at 60% CPU between 3 and 20 replicas, its label-printing workers scale with KEDA on queue length down to zero overnight, and the cluster autoscaler adds nodes on Monday mornings.
Don't confuse it with
- Manual scaling
- Predictable but slow to react; fine for steady loads.
- Bigger nodes
- Vertical scaling of the cluster; doesn't help if one app needs more copies.
Words to know
- HPA
- Changes the number of pod replicas to meet a target.
- KEDA
- Kubernetes Event-driven Autoscaling: scales on external events.
- Scale to zero
- Running no pods at all when there's no work.
Where to look
- kubectl get hpa
- kubectl top pods
Practise it
- Scale pods automaticallyHow-to, Costs money
- Scale on events with KEDAHow-to, Costs money
- Scale nodes: cluster autoscaler and KarpenterHow-to, Look only
- Set requests and limits, and understand QoS classesHow-to, Free
Read it in the guide, next to the tasks and labs.
Open in DevOps, Hands On