<p>I have a deployment where I need just one instance to be up at a time.  When gracefully shutting down the pod, another starts up immediately -- without waiting for the pod to finish exiting.  How can I make sure that the gracefully deleted pod is completely gone before the new pod starts up?</p>

<p>Things I've tried:
1. Rolling Update with maxSurge: 0 and maxUnavailable: 1</p>

<pre><code>  strategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate
</code></pre>

<p>Result: When gracefully deleting the pod, another instance immediately starts up, so there are two pods running at the same time, seemingly ignoring the maxSurge value.</p>

<ol start="2">
<li><p>Same as 1, except using percents instead of integers</p></li>
<li><p>Using Recreate instead of Rolling Update</p></li>
</ol>

<pre><code>strategy:
    type: Recreate
</code></pre>

<p>Result: same as 1</p>

<p>Is there a way to get the desired behavior directly in Kubernetes, or do you have to do something like add an init container with a delay, etc.?</p>

cmm
<p>Use <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">StatefulSets</a></p>

<pre><code>StatefulSets are valuable for applications that require one or more of the following.

 - Stable, unique network identifiers. 
 - Stable, persistent storage.
 - Ordered, graceful deployment and scaling. 
 - Ordered, automated rolling updates.
</code></pre>
