<p>I have some HPAs defined within a Kubernetes cluster and the scaling functionality works as expected. However, I've observed that the choice of specific pods that are chosen to be scaled down seems pretty arbitrary.</p>
<p>So the question is. Can I somewhere define criteria to choose which pods are preferred to be terminated when a scale-down event happens, but without explicitly defining that the pods are actively scaled on that criteria?</p>
<p>For example, I mainly care about CPU and scale such that the CPU percentage is maintained at 50% or less, but when scaling down would prefer that older pods are preferred to be terminated rather than newer ones, or pods consuming the most memory be terminated in preference to those consuming less memory.</p>
<p>I'm aware that I can explicitly scale on multiple criteria like CPU and memory, but this can be problematic and prevent downward scaling unnecessarily for example when memory is allocated to a cache but CPU usage has decreased.</p>

Colin
<p>As per this <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#pod-deletion-cost" rel="nofollow noreferrer">official doc</a>  You can add the annotation controller.kubernetes.io/pod-deletion-cost with a value in the range [-2147483647, 2147483647] and this will cause pods with lower value to be killed first. Default is 0, so anything negative on one pod will cause a pod to get killed during downscaling.</p>
<p>Find this <a href="https://github.com/kubernetes/enhancements/issues/2255" rel="nofollow noreferrer">gitlink</a>  about the implementation of this feature: Scale down a deployment by removing specific pods (PodDeletionCost) #2255.</p>
<p>You can also use Pod Priority and Preemption. Refer to this <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/" rel="nofollow noreferrer">official doc</a> for more information</p>
