During a Kubernetes scale-down, the kube-controller-manager decides which pod to delete first using several factors:
- Unhealthy pods: Pods with failed readiness or liveness probes are terminated first.
- Pod deletion cost: An annotation (
cluster-autoscaler.kubernetes.io/pod-deletion-cost) can prioritize pods; lower-cost pods are removed first. - Node balancing: Pods on nodes that would free up more resources or balance pod distribution are chosen.
- Creation order: Among equal-cost pods, those created later are deleted first.
In a ReplicaSet with identical pods, the default order is: randomized with a slight bias toward newer pods. Understanding this logic is crucial for DevOps interviews and production cluster management.