Difficulty: Advanced
What is the Cluster Autoscaler, how does it decide when to add or remove nodes, and how does it differ from the HPA and Karpenter?
The Cluster Autoscaler adds and removes nodes in a Kubernetes cluster. It scales up when Pods are Pending because no existing node has enough free requested CPU, memory or other resources, and scales down when nodes are underused and their Pods can safely move elsewhere. It acts on resource requests and scheduling, not on live CPU usage.
random, least-waste, most-pods, priority, or price on some clouds).Scale-up typically takes a minute or more because a VM has to boot and pull images. For latency-sensitive spikes, teams add overprovisioning: low-priority placeholder Pods that reserve space and get preempted when real Pods arrive.
A node is a candidate when the sum of requests on it is below a threshold (default 50 percent) for a sustained time (default 10 minutes), and all its Pods can be rescheduled elsewhere. Scale-down is blocked by:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"When a node is chosen, it is cordoned and drained gracefully, then the VM is deleted.
| Tool | Scales | Trigger |
|---|---|---|
| HPA | Pod replicas | CPU, memory or custom metrics |
| VPA | Pod requests | Observed usage history |
| Cluster Autoscaler | Nodes in predefined groups | Pending Pods and low utilisation |
| Karpenter | Nodes chosen on the fly | Pending Pods, with consolidation |
HPA and Cluster Autoscaler work together: during a Big Billion Days sale, HPA adds checkout Pods, they go Pending, and Cluster Autoscaler adds nodes. Karpenter (widely used on AWS EKS, with Azure support too) skips node groups and launches whichever instance type best fits the pending Pods, and actively consolidates to cheaper nodes. GKE Autopilot and node auto-provisioning hide this layer entirely.
balance-similar-node-groups.command:
- ./cluster-autoscaler
- --cloud-provider=aws
- --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/prod
- --expander=least-waste
- --balance-similar-node-groups=true
- --scale-down-utilization-threshold=0.5
- --scale-down-unneeded-time=10m
- --scale-down-delay-after-add=10m
- --skip-nodes-with-system-pods=true
Auto-discovery finds tagged ASGs; the scale-down flags shown are the defaults written out explicitly.
# Never evict this Pod for scale-down
kubectl annotate pod batch-report-x9 \
cluster-autoscaler.kubernetes.io/safe-to-evict="false"
# Why was a Pod not triggering scale-up?
kubectl describe pod checkout-5c7 | grep -i -A2 TriggeredScaleUp
kubectl -n kube-system get configmap cluster-autoscaler-status -o yaml
Events like TriggeredScaleUp or NotTriggerScaleUp on the Pod, plus the status ConfigMap, explain the autoscaler's decisions.
Cluster Autoscaler, Pending Pods, Node Groups, Scale-down, Karpenter