<p>I am trying to achieve 0 downtime during rolling update with EKS (AWS K8s service).</p>

<p>I have one WebSocket server and I want to ensure during the rolling update of this server, existing connections will be kept until the WebSockets are closed after the work is done.</p>

<p>I thought K8s rolling update feature would help me with this but it did not. I tried and it simply killed the pod while there were still connections to the WebSocket.</p>

<p>If I understand the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods" rel="noreferrer">document</a> correctly, then the pod termination goes like this:</p>

<ol>
<li>User signals pod deletion to K8s API</li>
<li>K8s stops routing new traffic to this pod and sends the SIGTERM signal</li>
<li>The application MUST handle this signal and start graceful termination of itself in a specified <code>grace-period</code> (default to 30s)</li>
<li>After that, K8s sends a SIGKILL signal to force terminate the pod.</li>
</ol>

<p>If my above understanding is correct, clearly there is no way to tell K8s to:</p>

<ol>
<li>Don't interrupt current connections</li>
<li>Let them run for as long as they need (they will eventually close but the period varies greatly)</li>
<li>Once all connections are closed, terminate the pod</li>
</ol>

<p><strong>Question</strong>: Is there any ways at all to make sure K8s:</p>

<ol>
<li>Doesn't interrupt WebSocket connection</li>
<li>Doesn't force the application to kill the connection in a specific <code>grace-period</code></li>
<li>Detects when all WebSocket connections are closed and kill the pod</li>
</ol>

<p>If anyone can assist me that would be greatly appreciated. </p>

<p>For mission critical application, go for customised blue-green deployments.</p>

<p>First deploy new version deployment with new selector and when all POD replicas are UP and ready to serve traffic, switch the service selector to point to new version deployment. </p>

<p>After this send the kill switch to older version which gracefully handles and disconnect all clients. So all new reconnections are forwarded to new version which is already set to serve traffic.</p>
