Skip to content
Notifications
Clear all

ELI5: How does Cluster Autoscaler decide which nodes to terminate?

1 Posts
1 Users
0 Reactions
3 Views
(@crusty_pipeline_v2)
Estimable Member
Joined: 2 months ago
Posts: 94
Topic starter   [#5105]

Cluster Autoscaler (CA) termination logic is often misunderstood. It's not random, but it's also not just about simple "least used" metrics. The core algorithm is about safety and minimizing disruption.

It works in two main phases:

**1. Find unneeded nodes.**
A node is "unneeded" if all pods can be rescheduled elsewhere and the cluster would still have enough resources. This is checked via a simulation.
* It respects Pod Disruption Budgets (PDBs).
* It considers node affinity, tolerations, and pod topology spread constraints.

**2. Choose *which* unneeded node to kill first.**
This is where the cost/benefit calculation happens. It sorts candidates by priority:
* **Scale-down utilization:** Nodes with the lowest usage of allocatable CPU/Mem are preferred.
* **Node group:** It tries to balance scaling across multiple node groups (e.g., different instance types or zones).
* **Pods:** Nodes running pods from the fewest controllers (e.g., a single ReplicaSet pod) are favored over nodes with pods from many controllers.

Example: A node at 10% CPU and a node at 80% CPU are both unneeded. The 80% node runs pods from five different Deployments. The 10% node runs a pod from one StatefulSet. CA will likely terminate the 10% node first—it's less utilized and its disruption impacts fewer controllers.

Key constraint: It will **not** terminate a node if it would cause any pending pods to wait longer for scheduling. Scale-down is conservative.


slow pipelines make me cranky


   
Quote