I want to implement the sticky session for a stateful app in Kubernetes. I was able to do that using sessionAffinity: ClientIP
but actually I am looking something in kubernetes which enables the session affinity on the client session using cookies. So, that if two sessions are coming from same client IP. It may get served by two different pods.
Asked
Active
Viewed 650 times
0

Nish
- 922
- 13
- 31
-
Did you start progress with this topic? please follow: [Configuring a backend service through Ingress](https://cloud.google.com/kubernetes-engine/docs/how-to/configure-backend-service) and [Sticky sessions](https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/) – Mark Sep 12 '19 at 09:59
1 Answers
0
Ingress Session Affinity
The support for Session Affinity on Ingress request depends on the implementation of the Ingress Controller that you are using.
E.g. the of Kubernetes community provided Nginx Ingress Controller does support some session affinity based on cookies.
In the example above, you can see that the response contains a Set-Cookie header with the settings we have defined. This cookie is created by NGINX, it contains a randomly generated key corresponding to the upstream used for that request (selected using consistent hashing) and has an Expires directive. If the user changes this cookie, NGINX creates a new one and redirects the user to another upstream.

Jonas
- 121,568
- 97
- 310
- 388