Autoscaling
HPA, VPA, Cluster Autoscaler, Karpenter, KEDA and the Cluster Proportional Autoscaler. Which one scales Pods, which one resizes them, and which one adds nodes.
Exam tasks: 4.2 (cloud native ecosystem and principles: elastic scaling)
The decision: is the problem too few Pods, Pods that are the wrong size, or too few nodes, and what signal should drive the fix?
Elasticity is a cloud native property: capacity follows load without a person in the loop. Kubernetes splits it into three layers. Pod count and Pod size scale the workload. Node count scales the cluster underneath it.
| Autoscaler | Scales | Driven by | Where it comes from |
|---|---|---|---|
| HPA | Replicas of a Deployment or StatefulSet | CPU and memory utilization, or custom and external metrics | Built into Kubernetes (autoscaling/v2) |
| VPA | CPU and memory requests of Pods | Observed usage history | Add-on from the Kubernetes autoscaler project |
| Cluster Autoscaler | Nodes in node groups | Pods stuck Pending for lack of capacity, and underused nodes | Add-on, works with cloud provider node groups |
| Karpenter | Nodes, picked to fit pending Pods | Pending Pods, consolidation | Kubernetes SIG Autoscaling subproject |
| Cluster Proportional Autoscaler | Replicas of one add-on, such as CoreDNS | Number of nodes or cores in the cluster, by a linear or ladder formula | Kubernetes autoscaler project add-on |
| KEDA | Replicas, including to and from zero | Event sources: queue depth, Kafka lag, cron, Prometheus queries | CNCF graduated project, drives an HPA under the hood |
- HPA utilization targets are a percentage of the Pod's requests. With no CPU request set, a CPU target has nothing to compare against.
- HPA and VPA should not both act on the same CPU or memory metric for one workload; they fight each other.
- Node autoscalers react to Pending Pods, not to high CPU on existing nodes. Pod autoscaling creates the Pods; node autoscaling makes room for them.
- In-place Pod resize (changing a running container's CPU and memory without recreating the Pod) became stable in Kubernetes v1.35, which lets vertical scaling avoid restarts in many cases.
Exam signal
"Scale workers to zero when the queue is empty and back up when messages arrive" is KEDA. Plain HPA keeps at least one replica by default.
Two layers working together
- The HPA reads metrics through the metrics APIs. Without metrics-server, CPU-based scaling has no data.
- The HPA scales up fast and scales down slowly. A stabilization window (five minutes by default) stops replica counts flapping when load wobbles.
- The Cluster Proportional Autoscaler is a different idea. It sizes a single add-on, usually CoreDNS, in proportion to the cluster, so a 500-node cluster gets more DNS replicas than a 5-node one. It does not look at load.
Autoscalers are not interchangeable
HPA changes the number of Pods. VPA changes the size of each Pod. Cluster Autoscaler changes the number of nodes. A question that says "the Pods are Pending because no node has room" is never solved by HPA or VPA.
Scenarios
Pending Pods for lack of resources are exactly what Cluster Autoscaler (or Karpenter) reacts to by adding nodes. VPA changes Pod size, which would make the shortage worse if it raised requests. A higher maxReplicas creates more Pending Pods. The scheduler can only place Pods on nodes that exist.
KEDA scales on event sources such as queue depth and can take a workload to and from zero. A plain CPU-driven HPA has no signal when there are no Pods to measure. The Cluster Proportional Autoscaler follows cluster size, not load, and VPA resizes Pods instead of changing how many exist.
The Cluster Proportional Autoscaler sets replicas of a target workload from the node or core count. Cluster Autoscaler adds nodes rather than replicas of one add-on. An HPA reacts to utilization, which can lag behind the timeout problems users see. kube-proxy programs Service rules and does not scale anything.
Related
Further reading
Cloud native principles
What "cloud native" means in the CNCF definition, microservices vs monoliths, immutability and declarative APIs, and serverless with Knative.
CNCF ecosystem and projects
The CNCF landscape, the sandbox, incubating and graduated maturity levels and what each requires, and which graduated project does which job.