<p><strong>Summary</strong></p>

<p>Can I give a deployment the rollout strategy <code>Recreate</code> and also set a fixed <code>maxSurge</code> for the deployment?</p>

<p><strong>More details</strong></p>

<p>I am developing an application that runs in Kubernetes. The backend will have multiple replicas, and runs EF Core with database migrations. I understand there are several ways to solve this; here's my idea at the moment.</p>

<p>On a new release, I would like all replicas to be stopped. Then a single replica at a time should start, and for each replica there should be an init container that runs the migrations (if needed).</p>

<p>This seems to be possible, using the following two configuration values:</p>

<ul>
<li><code>.spec.strategy.type==Recreate</code> and</li>
<li><code>.spec.strategy.rollingUpdate.maxSurge==1</code></li>
</ul>

<p>Is it possible to use these two together? If not, is there any way to control how many replicas a controller will start at once with the <code>Recreate</code> strategy?</p>

<p><strong>"No! You should do this in a completely different way!"</strong></p>

<p>Feel free to suggest other methods as well, if you think I am coming at this from the completely wrong angle.</p>

MW.
<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">Statefulset</a> might help you in this case.</p>

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

<ul>
<li>Stable, unique network identifiers.</li>
<li>Stable, persistent storage.</li>
<li>Ordered, graceful deployment and scaling.</li>
<li>Ordered, automated rolling updates.</li>
</ul>
