Sub topic 8
Cluster Autoscaler scale-down
This chapter assumes you know Pods, Deployments, resource requests, and how the Cluster Autoscaler (CA) adds nodes to a node group. Here you will see how it removes them.
How scale-down decides
Every scan interval (10 seconds by default), the CA checks each node for underutilization. It sums the resource requests of the pods on the node and divides by the node's allocatable capacity. If both CPU and memory fall below --scale-down-utilization-threshold (0.5 by default), the node is a removal candidate.
Utilization is calculated from requests, not live usage. A node running idle pods that request a lot still looks busy.
A candidate is not removed at once. It must stay unneeded for --scale-down-unneeded-time (10 minutes by default). After a scale-up, the CA also waits --scale-down-delay-after-add (10 minutes by default) before it considers any removal.
The safety simulation
Before marking a node unneeded, the CA simulates moving every pod on it to the other nodes. If any pod has nowhere to go, the node stays. The CA will also refuse to remove a node that holds:
- Pods not managed by a controller, such as bare pods.
- Pods using local storage (
emptyDirorhostPath), unless they carry the safe-to-evict annotation. - Pods whose eviction would violate a PodDisruptionBudget.
- Pods with the annotation
cluster-autoscaler.kubernetes.io/safe-to-evict: "false". - Kube-system pods without a PodDisruptionBudget (controlled by
--skip-nodes-with-system-pods).
Controlling individual pods and nodes
Annotate a pod to block or allow eviction:
apiVersion: v1
kind: Pod
metadata:
name: batch-worker
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
spec:
containers:
- name: worker
image: registry.k8s.io/pause:3.9To keep a whole node, annotate the Node with cluster-autoscaler.kubernetes.io/scale-down-disabled=true:
kubectl annotate node ip-10-0-1-23.ec2.internal \
cluster-autoscaler.kubernetes.io/scale-down-disabled=trueRemoval
For a chosen node, the CA taints it ToBeDeletedByClusterAutoscaler so nothing new lands there. It then evicts the pods, respecting their termination grace period and PodDisruptionBudgets. Finally it asks the cloud provider to terminate the instance and shrink the group.
The CA never shrinks a group below its configured minimum size.
Common errors
- Node never leaves. Read the CA status ConfigMap or logs. They name the blocking pod, for example "not enough pod disruption budget" or "pod is not replicated".
- Nodes leave too slowly. Lower
--scale-down-unneeded-time, accepting more churn. - Utilization looks low but removal fails. A single pod with a restrictive PodDisruptionBudget or a local-storage volume blocks the whole node.
Exercise
A node runs at 20% CPU and memory requests. Ten minutes later the CA still has not removed it. Name two likely causes.
Show answer
A pod on the node cannot be rescheduled elsewhere or is protected (a bare pod, local storage, a safe-to-evict "false" annotation, or a PodDisruptionBudget that allows no evictions). Alternatively, the node was in the delay window after a recent scale-up, or it carries the scale-down-disabled annotation, or the node group is already at its minimum size.