In correlation with the end of life (EOL) for MKE 3.6.x, maintenance of this documentation set was discontinued as of 2024-OCT-13. Click here for the latest MKE 3.x version documentation. 
        
        Configure a sticky session¶
Sticky sessions enable users who participate in split testing to consistently see a particular feature. Adding sticky sessions to the initial request forces NGINX Ingress Controller to route follow-up requests to the same Pod.
- Enable the sticky session in the Kubernetes Ingress resource: - nginx.ingress.kubernetes.io/affinity: "cookie" 
- Specify the name of the required cookie (default: - INGRESSCOOKIE).- nginx.ingress.kubernetes.io/session-cookie-name: "<cookie-name>" 
- Specify the time before the cookie expires (in seconds): - nginx.ingress.kubernetes.io/session-cookie-max-age: "<cookie-duration>" 
The following is an example of a Kubernetes Ingress configuration file with a sticky session enabled:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sticky-session-test
  annotations:
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
spec:
  rules:
  - host: stickyingress.example.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /
Note
NGINX Ingress Controller only supports cookie-based sticky sessions.
See also
Sticky sessions in the NGINX Ingress Controller documentation.