<p>(Before I start, I'm using minikube v27 on Windows 10.)</p>

<p>I have created a deployment with the nginx 'hello world' container with a desired count of 2:</p>

<p><a href="https://i.stack.imgur.com/L46pe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/L46pe.png" alt="pods before scaling up"></a></p>

<p>I actually went into the '2 hours' old pod and edited the index.html file from the welcome message to "broken" - I want to play with k8s to seem what it would look like if one pod was 'faulty'.</p>

<p>If I scale this deployment up to more instances and then scale down again, I almost expected k8s to remove the oldest pods, but it consistently removes the newest:</p>

<p><a href="https://i.stack.imgur.com/reAxW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/reAxW.png" alt="pods after scaling down"></a></p>

<p>How do I make it remove the oldest pods first?</p>

<p>(Ideally, I'd like to be able to just say "redeploy everything as the exact same version/image/desired count in a rolling deployment" if that is possible)</p>

<p>Pod deletion preference is based on a ordered series of checks, defined in code here:</p>

<p><a href="https://github.com/kubernetes/kubernetes/blob/release-1.11/pkg/controller/controller_utils.go#L737" rel="noreferrer">https://github.com/kubernetes/kubernetes/blob/release-1.11/pkg/controller/controller_utils.go#L737</a></p>

<p>Summarizing- precedence is given to delete pods:</p>

<ul>
<li>that are unassigned to a node, vs assigned to a node</li>
<li>that are in pending or not running state, vs running</li>
<li>that are in not-ready, vs ready</li>
<li>that have been in ready state for fewer seconds</li>
<li>that have higher restart counts</li>
<li>that have newer vs older creation times</li>
</ul>

<p>These checks are not directly configurable. </p>

<p>Given the rules, if you can make an old pod to be not ready, or cause an old pod to restart, it will be removed at scale down time before a newer pod that is ready and has not restarted.</p>

<p>There is discussion around use cases for the ability to control deletion priority, which mostly involve workloads that are a mix of job and service, here:</p>

<p><a href="https://github.com/kubernetes/kubernetes/issues/45509" rel="noreferrer">https://github.com/kubernetes/kubernetes/issues/45509</a></p>
