Sticky sessions
Sticky sessions, or session persistence, is when you instruct the load balancer to remain linked to a specific node (server) to avoid losing the session data if the request goes to the other server. Essentially, you send the request from a given IP to the delivery server, but continue to send follow-up requests to the same server until the session expires. Session persistence is needed when the project has transactions or required data in the session.
Sticky sessions are typically used in situations where you have some data in the session and the sessions are not replicated between servers, but you also need to ensure that the data doesn’t get lost.
Only paths on the Ingress using nginx.ingress.kubernetes.io/affinity
use session cookie affinity.
All paths defined on other Ingresses for the host are load balanced through the random selection of a backend server.
For more on sticky sessions, see Kubernetes: Sticky sessions. |
Enable sticky sessions
To enable sticky sessions:
-
Go to your
values.yml
file in your DX Cloud project. -
Set the following ingress annotations:
ingress: enabled: true annotations: kubernetes.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/proxy-body-size: 512m cert-manager.io/cluster-issuer: "letsencrypt-prod-dns" nginx.ingress.kubernetes.io/affinity: "cookie" (1) nginx.ingress.kubernetes.io/affinity-mode: "persistent" (2) nginx.ingress.kubernetes.io/session-cookie-name: "INGRESSCOOKIE" (3) nginx.ingress.kubernetes.io/session-cookie-max-age: "3600" (4) nginx.ingress.kubernetes.io/default-backend: {{ .Env.DEPLOYMENT }}-magnolia-error-page-svc nginx.ingress.kubernetes.io/custom-http-errors: "503" hosts: - host: {{ .Env.DEPLOYMENT }}.eu-playground.magnolia-platform.com paths: - path: / instance: public - path: /author instance: author .....
1 Set nginx.ingress.kubernetes.io/affinity
tocookie
.2 Set nginx.ingress.kubernetes.io/affinity-mode
topersistent
.3 Put the INGRESSCOOKIE
atnginx.ingress.kubernetes.io/session-cookie-name
.4 Set nginx.ingress.kubernetes.io/session-cookie-max-age
to the time (in seconds) you want the cookie to persist. After this configured time, the cookie is deleted.