简体   繁体   中英

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

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.

Ingress Session Affinity

The support for Session Affinity on Ingress request depends on the implementation of the Ingress Controller that you are using .

Eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM