Sub topic 5
How the Cluster Autoscaler Works
This chapter assumes you know Pods, Deployments and Nodes, how resource requests work, and what an AWS Auto Scaling group (ASG) is. It covers the Cluster Autoscaler's control loop. Later chapters cover scale-up and scale-down in detail.
What it is
The Cluster Autoscaler (CA) is a Deployment that runs in your cluster, usually in kube-system. It does not create nodes itself. It changes the desired size of existing node groups, such as ASGs on AWS, and the cloud provider launches or terminates the machines.
CA only reacts to scheduling facts. It looks at Pending pods and at node utilization. It does not look at CPU graphs.
The control loop
CA runs a loop, every 10 seconds by default (--scan-interval). Each pass does the following:
- Reads all nodes, pods and node groups from the API server and the cloud provider.
- Finds pods that are Pending with the
Unschedulablecondition set by the scheduler. - If there are any, simulates whether adding a node from some node group would let them schedule. If so, it raises that group's desired size.
- If there are no such pods, checks for nodes that are underused and could be removed.
Simulation is the core idea
CA does not guess. For each node group it builds a template node from the group's instance type, labels and taints. It then runs the scheduler's own predicate logic against that template to ask: would the Pending pods fit here? The same simulation, run in reverse, decides whether the pods on a node could move to other nodes.
This explains most surprises:
- A pod with no resource requests looks free to the simulator, so CA may not scale for it.
- A pod that no node group template can satisfy, for example because of a node selector, stays Pending forever. CA records that it did not help.
- Node groups scaled to zero rely on the template, because there is no live node to copy.
What CA needs to see
| Input | Source | Why it matters |
|---|---|---|
| Pod requests | Pod spec | Used for fit and utilization, not actual usage |
| Pending condition | Scheduler | The only trigger for scale-up |
| Node group bounds | ASG min and max | CA never goes outside them |
| Group membership | Cloud provider | Maps nodes to the groups CA may resize |
Observing the loop
CA writes a status ConfigMap and emits events on pods it considers. Check them first when nodes do not appear.
kubectl -n kube-system get configmap cluster-autoscaler-status -o yaml
kubectl describe pod <pending-pod> | grep -A5 EventsLook for TriggeredScaleUp or NotTriggerScaleUp events. The second one includes the reason, such as no group matching the pod's constraints.
Exercise
A pod has been Pending for ten minutes, and the Cluster Autoscaler did not add a node. The pod's nodeSelector asks for a label that none of your node groups carry. Why does CA do nothing, and what are two ways to fix it?
Show answer
CA simulates the pod against a template node for each group. No template has the label, so the pod cannot fit anywhere and CA emits a NotTriggerScaleUp event. Fix it by adding the label to a node group's launch template or tags so the template carries it, or by removing or changing the nodeSelector on the pod.