My architecture is as follows;
- Kubernetes (GKE)
- nginx reverse proxy deployment fronted by "LoadBalancer" service
- Python + Flask WSGI app
This works perfectly as long as there is only ONE Flask pod. As soon as the replica count is increased beyond 1 then sessions completely break down since now the session set in one request is forgotten in the next (request will hit different pods every time instead of the one that remembers the session).
I want to implement sticky sessions somehow. When I google how to solve this I find two types of answers, both of which does not help me;
- Put ip_hash directive into nginx config. This does not work because I am relying on the name resolution built into kubernetes to reach the flask app from nginx (I just refer to it by a single name "app". for ip_hash to work, each downstream server needs to be mentioned by name in the nginx config)
- Configure nginx ingress controller to use sticky sessions. This does not work because.... I don't use ingress at all. I use a custom nginx (community edition) running in a pod fronted by a LoadBalancer service entry.
What options exist for sticky sessions in my setup?
Do I need to switch my architecture to ingress to have sticky sessions?
Can't I somehow decorate requests with the pod id and route based on that in nginx?