<p>I have 4 replicas of a deployment running that consumer from Kafka and do some processing.</p>
<p>When I come to deploying a new version of the application, 4 new pods are created before the existing pods are removed and in the termination grace period, the consumers will rebalance the work across all 8 pods before they exit. They will then rebalance again once the original pods are terminated.</p>
<p>This means that the data they work on during the rebalancing is effectively lost as the work is stateful so nothing meaningful can be done during this handover time.</p>
<p>The ideal solution would be:</p>
<ul>
<li>The running pods are signalled to terminate</li>
<li>They save their current state</li>
<li>New pods are started and rebalance the Kafka partitions</li>
<li>Initial state is fetched by new pods</li>
<li>Profit</li>
</ul>
<p>I am not worrying about how to save/pass the state at the moment but would like to avoid the necessary rebalancing and resulting output data that comes from having the new pods be created before the old ones terminated</p>
<p><strong>I appreciate that this will mean that service can be interrupted if the new version has issues</strong>. The consumers are far faster than the data coming in and will catchup, being down for multiple hours would be fine.</p>
<p><strong>What configuration can I set in the kubeconfig of my deployment to signal kubernetes to change the order of its deployment strategy?</strong></p>

hi im Bacon
<p>Default update strategy is <code>RollingUpdate</code>, which causes to observed behavior. You can set it to <code>Recreate</code>, by setting <code>spec.strategy.type</code> like:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: some-app
spec:
  replicas: 3
  strategy:
    type: Recreate
[...]
</code></pre>
<p>From <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#recreate-deployment" rel="nofollow noreferrer">docs</a> on that strategy:</p>
<blockquote>
<p>All existing Pods are killed before new ones are created</p>
</blockquote>
