i’m running a flask-socketio behind an ingress.
here’s the config:
socketio = SocketIO(app, message_queue='redis://redis-server.domain:6379')
in the dockerfile, it runs like so:
CMD ["gunicorn", "-k", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", "-w", "4", "--bind", "0.0.0.0:2731", "app:app"]
and the ingress is configured like this:
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/enable-ssl-passthrough: "true"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
i also tried replacing "cookie" with "ip_hash"
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.
any ideas?
2
Answers
i've selected Harsh Manvar's ansewer as the correct one, but adding details for future reference:
in the service, sessionAffinity: ClientIP as suggested.
the Run command in dockerfile:
the requirements.txt:
the socketio:
added to ingress:
Ideally, it should have worked but try this .spec.sessionAffinity
Set it to service
.spec.sessionAffinity
value will be ClientIPService to POD sticky session