Cluster Autoscaler

Difficulty: Advanced

Question

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?

Answer

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.

How scale-up works

  1. The scheduler fails to place a Pod and marks it unschedulable.
  2. The Cluster Autoscaler (which checks every 10 seconds by default) sees the Pending Pod.
  3. For each node group (AWS Auto Scaling Group, GCP Managed Instance Group, Azure VM Scale Set), it simulates whether a new node built from that group's template would fit the Pod, including labels, taints and zones.
  4. An expander picks one group (random, least-waste, most-pods, priority, or price on some clouds).
  5. It increases that group's desired size; the cloud boots a VM, it joins the cluster, and the scheduler places the Pod.

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.

How scale-down works

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:

  • PodDisruptionBudgets that would be violated
  • Pods not managed by a controller (bare Pods)
  • Pods annotated with cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
  • Pods with restrictive affinity or node selectors that cannot fit elsewhere
  • Some kube-system Pods without a PDB, and node groups already at their minimum size

When a node is chosen, it is cordoned and drained gracefully, then the VM is deleted.

How it fits with other autoscalers

ToolScalesTrigger
HPAPod replicasCPU, memory or custom metrics
VPAPod requestsObserved usage history
Cluster AutoscalerNodes in predefined groupsPending Pods and low utilisation
KarpenterNodes chosen on the flyPending 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.

Gotchas

  • Missing requests break it: Pods without requests look like they need nothing, so nodes appear empty and the autoscaler makes poor decisions.
  • Version match: run a Cluster Autoscaler release that matches your Kubernetes minor version.
  • Zonal storage: a Pod bound to an EBS volume in one zone needs a node group in that zone; use one group per zone with balance-similar-node-groups.
  • Limits: set node group min and max sizes so a runaway Deployment cannot launch hundreds of VMs and a large cloud bill.
Cluster Autoscaler scale-up path. Scale-up is driven by unschedulable Pods, not by CPU usage on nodes.
  1. Pod stays Pending: No node has enough free requested resources.
  2. Autoscaler detects it: Its loop runs every 10 seconds by default.
  3. Simulate node groups: Checks which group's template would fit the Pod.
  4. Expander picks a group: For example least-waste or priority.
  5. Cloud adds a VM: Desired size of the ASG, MIG or VMSS increases.
  6. Scheduler places the Pod: The new node joins and the Pod starts.

Code examples

Key Cluster Autoscaler flags (container args)

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.

Protect a Pod from scale-down and debug decisions

# 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.

Key points

  • Scale-up is triggered by Pending Pods, not by high node CPU
  • Decisions are based on resource requests, so every Pod needs requests
  • Scale-down: under 50 percent requested for 10 minutes by default and Pods movable
  • PDBs, bare Pods and safe-to-evict=false annotations block scale-down
  • Karpenter is the main alternative: no fixed node groups, active consolidation

Common follow-up questions

  • Your HPA scaled up but Pods are Pending for 5 minutes. How do you reduce that delay?
  • Why did the Cluster Autoscaler not remove an obviously empty node?
  • How does Karpenter differ from the Cluster Autoscaler?
  • How do you handle autoscaling for Pods that need GPU nodes?

Interview tips

  • Emphasise that it reacts to Pending Pods and requests, not to utilisation metrics; many candidates get this wrong
  • Explain how HPA and Cluster Autoscaler chain together during a traffic spike
  • Mention Karpenter to show awareness of current tooling

Concepts covered

Cluster Autoscaler, Pending Pods, Node Groups, Scale-down, Karpenter

More Kubernetes & Orchestration questions