Skip to content

Cookie affinity breaks for multiple ingresses on same host with different session-cookie-path

What happened:

When more than one ingress is defined for a single host, and at least two use the nginx.ingress.kubernetes.io/affinity: cookie annotation, if each of them uses a different nginx.ingress.kubernetes.io/session-cookie-path annotation, then those ingress' paths are load balanced randomly between the backend servers (ignoring the cookie affinity).

What you expected to happen:

I expected the load balancing would follow the cookie affinity.

The load balancing did not follow the cookie affinity, instead it was distributed randomly between the backend servers. I suspect the lua code doing the cookie affinity distribution does not account for this situation.

NGINX Ingress controller version (exec into the pod and run /nginx-ingress-controller --version): v1.12.7

Kubernetes version (use kubectl version): v1.31.13-eks-113cf36

How to reproduce this issue:

  1. Create 2 ingresses for the same host
    • Backend for each ingress should be the same, but pointing to at least 2 different servers
    • Set the nginx.ingress.kubernetes.io/affinity: cookie annotation on both
    • Set the nginx.ingress.kubernetes.io/session-cookie-path annotation on each, but different (in my case /path on one and /path/sub-path on other)
  2. Visit one of the load balanced paths repeatedly, find that the load balancing is distributing randomly between the backend servers