<p>I've a deployment whose app makes a lock on a file, and crash if there's any existing lock. How can I ask Kubernetes to remove the old pod before spinning up the new one ?</p>
<p>I know you usually want the opposite, spinning up the new, and only when it's ready remove the old, to avoid downtime. For this case I don't care, it's typesense in a developments environments, we're using the SaaS for staging &amp; production.</p>
<p>Thanks for any help !</p>

Rémy
<p>Easiest way to achieve that is to set the upgrade strategy to <code>Recreate</code>.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
[...]
spec:
  selector:
[...]
  strategy:
    type: Recreate
  template:
[...]
</code></pre>
<p>From <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#recreate-deployment" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>All existing Pods are killed before new ones are created when .spec.strategy.type==Recreate.</p>
</blockquote>
