Cluster Autoscaler
Cluster Autoscaler is a Kubernetes component that adds worker nodes when pods cannot be scheduled for lack of resources, and removes underused nodes to cut cost. It scales nodes, whereas the Horizontal Pod Autoscaler scales pods.
How the two layers fit together
HPA adds pods when load rises. If the nodes are full, those new pods stay Pending, and that is the signal Cluster Autoscaler (CA) waits for. It simulates whether a new node from a configured node group would let the pending pods schedule, then asks the cloud provider to grow the group.
ASG or MIG"] A -->|"new node joins"| N["Pods scheduled"] classDef k8s fill:#326CE5,color:#ffffff classDef warn fill:#FFEDD5,color:#1E293B classDef cloud fill:#EDE9FE,color:#1E293B classDef ok fill:#D1FAE5,color:#1E293B class H,C k8s class P warn class A cloud class N ok
Scale-up typically takes one to a few minutes because a real VM must boot, join the cluster, and pull images. When nodes sit mostly idle for a configured time, CA drains and removes them.
Key flags
command: - ./cluster-autoscaler - --cloud-provider=aws - --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/mumbai-prod-cluster - --expander=least-waste - --balance-similar-node-groups - --scale-down-delay-after-add=10m - --scale-down-unneeded-time=10m - --scale-down-utilization-threshold=0.5Use a CA version whose minor release matches your cluster's Kubernetes minor version. On AWS, grant it permissions through IAM roles for service accounts, not node-wide credentials.
Protecting workloads from scale-down
metadata: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "false"Also use a PodDisruptionBudget so CA cannot drain a node if it would drop a service below its minimum.
When scale-down is blocked
- Pods without a controller, such as bare pods
- Pods with local storage or restrictive PodDisruptionBudgets
- Pods carrying the
safe-to-evict: "false"annotation
RememberIf traffic can spike faster than a node boots, such as at the start of a live match on a platform like Hotstar, run low-priority placeholder pods that real pods preempt instantly.
SecurityAlways set a
maxSizeon node groups. A runaway HPA or batch job can otherwise provision hundreds of nodes and a very large cloud bill.
Common MistakeSetting
scale-down-delay-after-addtoo low. CA adds a node, sees a dip, removes it, then re-adds it minutes later, causing churn and pod disruption.
Frequently Asked Questions
How does Cluster Autoscaler decide to add a node?
It reacts to pods stuck Pending because the scheduler found no node with enough free resources. It then checks whether a node from an existing node group would allow them to schedule. It does not look at CPU utilisation directly.
What is the difference between Cluster Autoscaler and Karpenter?
Cluster Autoscaler scales pre-defined node groups, while Karpenter provisions individual nodes directly, choosing instance types to fit the pending pods. Karpenter often provisions faster and packs more flexibly, while CA works across many cloud providers.
Why will a node not scale down even though it is almost empty?
A single pod that cannot be safely evicted pins it, for example a pod with no controller, local-only data, or a restrictive PodDisruptionBudget. Check the CA logs for the reason it marked the node as not removable.