Sub topic 6
Cluster Autoscaler scale-up
This chapter assumes you know Pods, Deployments and Nodes, how resource requests work, and how to use kubectl and YAML. It also assumes you know what an AWS Auto Scaling group is. The previous chapter covered the Cluster Autoscaler control loop. Here you follow one scale-up decision from start to finish.
What triggers a scale-up
The Cluster Autoscaler (CA) does not watch CPU or memory usage. It watches for pods that the scheduler marked unschedulable. A pod in that state is Pending, and its PodScheduled condition is False with the reason Unschedulable.
On each loop (every 10 seconds by default), the CA does the following:
- Lists the unschedulable pods.
- For each node group, builds a template node from the group's instance type, labels and taints.
- Simulates whether the pending pods would fit on that template node.
- Keeps the node groups where at least one pod fits.
- Applies the expander to choose one group, and asks the cloud provider to raise that group's desired size.
Try it
Apply the inflate Deployment from the Topic Spine. It starts at zero replicas and requests 1 CPU and 1Gi per pod.
apiVersion: apps/v1
kind: Deployment
metadata:
name: inflate
spec:
replicas: 0
selector:
matchLabels:
app: inflate
template:
metadata:
labels:
app: inflate
spec:
containers:
- name: inflate
image: registry.k8s.io/pause:3.9
resources:
requests:
cpu: "1"
memory: 1GiThen create demand and watch the result:
kubectl scale deployment inflate --replicas=10
kubectl get pods -l app=inflate
kubectl describe pod -l app=inflate | grep -A5 Events
kubectl get nodes -wThe pod events first show FailedScheduling from the scheduler, such as 0/3 nodes are available: Insufficient cpu. Shortly after, the CA adds TriggeredScaleUp, naming the group and its new size. When the new node becomes Ready, the pods move from Pending to Running.
Bin-packing and batching
The CA does not add one node per pod. During simulation it packs pending pods onto imagined nodes of the template shape. Ten pods that each request 1 CPU need about three nodes with 4 CPUs each, after allowing for system overhead. The CA then raises the group's size by that count in one step.
Scale-up is also limited by:
- The group's configured maximum size.
- Cloud quotas, such as EC2 vCPU limits.
- The
--max-nodes-totalflag, which caps the whole cluster.
Why a scale-up does not happen
| Symptom | Likely cause |
|---|---|
| No `TriggeredScaleUp` event, pod stays Pending | The pod does not fit any template node. Its requests may exceed the largest instance, or a selector, affinity or taint matches no group. |
| `NotTriggerScaleUp` event | The CA simulated every group and none helps. The event lists the reason per group. |
| Group size rises but no node joins | The cloud call failed (quota, capacity, bad launch template), or the node cannot register. |
| Pod is Pending for a reason other than resources | Examples are an unbound PersistentVolumeClaim or a missing image pull secret. More nodes will not fix these. |
When a group's size rises but no node registers within --max-node-provision-time (15 minutes by default), the CA marks the group unhealthy and backs off from it. It then tries another group on later loops.
Exercise
Ten pods each request 3 CPUs, but your largest node group uses instances with 2 vCPUs. The pods stay Pending and the CA never logs TriggeredScaleUp. Why, and what do you change?
Show answer
The CA simulates each pod on a template node from every group. A 3-CPU pod cannot fit on a 2-vCPU node, so no group helps and the CA does nothing. Either lower the pod's CPU request or add a node group with larger instances (at least 4 vCPUs, since some capacity is reserved for system use).