From 10162f7776ba34f804146b1bc466cf6ee17b23f1 Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Wed, 10 Mar 2021 12:16:54 -0500 Subject: [PATCH] Add description of replica controller scaledown sort logic --- .../docs/concepts/workloads/controllers/replicaset.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/en/docs/concepts/workloads/controllers/replicaset.md b/content/en/docs/concepts/workloads/controllers/replicaset.md index e45d20c8f7..cade83afa5 100644 --- a/content/en/docs/concepts/workloads/controllers/replicaset.md +++ b/content/en/docs/concepts/workloads/controllers/replicaset.md @@ -310,6 +310,17 @@ assuming that the number of replicas is not also changed). A ReplicaSet can be easily scaled up or down by simply updating the `.spec.replicas` field. The ReplicaSet controller ensures that a desired number of Pods with a matching label selector are available and operational. +When scaling down, the ReplicaSet controller chooses which pods to delete by sorting the available pods to +prioritize scaling down pods based on the following general algorithm: + 1. Pending (and unschedulable) pods are scaled down first + 2. If controller.kubernetes.io/pod-deletion-cost annotation is set, then + the pod with the lower value will come first. + 3. Pods on nodes with more replicas come before pods on nodes with fewer replicas. + 4. If the pods' creation times differ, the pod that was created more recently + comes before the older pod (the creation times are bucketed on an integer log scale) + +If all of the above match, then selection is random. + ### ReplicaSet as a Horizontal Pod Autoscaler Target A ReplicaSet can also be a target for