<p>i'm running a flask-socketio behind an ingress.
here's the config:</p>
<pre><code>socketio = SocketIO(app, message_queue='redis://redis-server.domain:6379')
</code></pre>
<p>in the dockerfile, it runs like so:</p>
<pre><code>CMD [&quot;gunicorn&quot;, &quot;-k&quot;, &quot;geventwebsocket.gunicorn.workers.GeventWebSocketWorker&quot;, &quot;-w&quot;, &quot;4&quot;, &quot;--bind&quot;, &quot;0.0.0.0:2731&quot;, &quot;app:app&quot;]
</code></pre>
<p>and the ingress is configured like this:</p>
<pre><code>nginx.ingress.kubernetes.io/affinity: &quot;cookie&quot;
nginx.ingress.kubernetes.io/enable-ssl-passthrough: &quot;true&quot;
nginx.ingress.kubernetes.io/session-cookie-name: &quot;route&quot;
</code></pre>
<p>i also tried replacing &quot;cookie&quot; with &quot;ip_hash&quot;</p>
<p>whenever i add a second replica pod, it starts returning error 400, as if it contacts the pods interchangeably, and not sticking to the same server, thus breaking the socket.</p>
<p>any ideas?</p>

Benny
<p>i've selected Harsh Manvar's ansewer as the correct one, but adding details for future reference:</p>
<p>in the service, sessionAffinity: ClientIP as suggested.</p>
<p>the Run command in dockerfile:</p>
<pre><code>CMD [&quot;gunicorn&quot;, &quot;-k&quot;, &quot;geventwebsocket.gunicorn.workers.GeventWebSocketWorker&quot;, &quot;-w&quot;, &quot;1&quot;, &quot;--bind&quot;, &quot;0.0.0.0:6138&quot;, &quot;--timeout&quot;, &quot;180&quot;, &quot;app:app&quot;]
</code></pre>
<p>the requirements.txt:</p>
<pre><code>gunicorn
simple-websocket
gevent-websocket
gevent
</code></pre>
<p>the socketio:</p>
<pre><code>socketio = SocketIO(app, message_queue='redis://redis-service.redis:6379')
</code></pre>
<p>added to ingress:</p>
<pre><code>nginx.ingress.kubernetes.io/enable-ssl-passthrough: &quot;true&quot;
nginx.ingress.kubernetes.io/add-base-url: &quot;true&quot;
nginx.ingress.kubernetes.io/session-cookie-name: &quot;route&quot;
nginx.ingress.kubernetes.io/websocket-services: service-name
nginx.ingress.kubernetes.io/session-cookie-expires: &quot;172800&quot;
nginx.ingress.kubernetes.io/session-cookie-max-age: &quot;172800&quot;
</code></pre>
