How Kubernetes autoscaling works

Knowledge Videos

Short animated explainers, organised by subject.

How Kubernetes autoscaling works

The HPA formula and its metrics, requests and scale-down stabilisation, the Vertical Pod Autoscaler, the Cluster Autoscaler and Karpenter for nodes, and KEDA for event-driven scaling.

Transcript

Traffic changes during the day. Autoscaling adds capacity when load rises and removes it when load drops, so you only pay for what you need.

The Horizontal Pod Autoscaler, or HPA, changes the number of pod replicas. Every fifteen seconds it reads metrics, such as CPU, from the metrics server.

The rule: desired replicas equals current replicas times current metric divided by target metric, rounded up. Twice the target load means twice the pods.

Pods need resource requests, because CPU utilisation is measured against the request. Scaling down is deliberately slow, with a stabilisation window, so replicas do not flap.

The Vertical Pod Autoscaler tunes the CPU and memory requests of each pod instead, but applying new values usually restarts the pod.

More pods need room. The Cluster Autoscaler, or Karpenter, adds nodes when pods are Pending because nothing fits, and removes nodes that sit mostly empty.

For event-driven workloads, KEDA scales on queue length or custom metrics, and can even scale down to zero pods.

Together: HPA adds pods, the cluster autoscaler adds nodes, and readiness probes with shared Redis sessions keep users unaware.

Measure. Scale pods. Scale nodes.

More in this series