Session Affinity in kubernetes based on Client session not on Client IP

818 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.