Sticky session in Kubernetes

As we know RESTful API is stateless, every request will be forward to backend server by round robin mechanism.

But in some scenario we need sticky session which means request from one client should be forward to one backend server.

After checking kubernetes documentation we added some annotations under ingress configuration, and it works well.

annotations:
  nginx.ingress.kubernetes.io/affinity: "cookie"
  nginx.ingress.kubernetes.io/session-cookie-name: "router"
  nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"

If you open Developer Tools in Chrome, you will find the cookie.