sticky sessions in nginx-ingress-controller not working

8/27/2018

I'm diving in to an issue with an existing kubernetes cluster, non EKS , setup on AWS. We're trying to get sticky session support enabled, and I just can't get it working. I've followed the docs and no luck. Here's where I'm at now:

I've made these changes to our helm templates (both with and without the nginx prefix at the front of the annotation) . I haven't figured out how to check what version of the nginx-ingress-controller we're using so I've tried both and I know that the annotation has changed back in Dec of 17.

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

Deployed the changes and when I describe the ingress I can see it was deployed by describing the ingress (again, with and without the nginx prefix). I really don't think this part is right, because examples I've seen is that everything before the / for the sticky annotations shouldn't be there, yet here they are.

Annotations:
    ingress.kubernetes.io/affinity:             cookie
    ingress.kubernetes.io/session-cookie-hash:  sha1
    ingress.kubernetes.io/session-cookie-name:  route
    kubernetes.io/ingress.class:                nginx

But when I do a curl request I can see the cookie is not going to be set:

curl -I  https://test.com/hello
HTTP/2 200 
server: nginx/1.11.3
date: Mon, 27 Aug 2018 20:26:37 GMT
content-type: application/json; charset=utf-8
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
etag: W/"93a23971a914e5eacbf0a8d25154cda3"
cache-control: max-age=0, private, must-revalidate
x-request-id: fc91644f-a4b6-475b-9fb5-ccabe0551038
x-runtime: 0.006894
strict-transport-security: max-age=15724800; includeSubDomains; preload
vary: Origin

Again, I have tested with and without the nginx. prefix for the sticky annotations and there has been no change, so I must be missing something.

-- Rick Baker
kubernetes

1 Answer

7/19/2019

Found my old question that was unanswered. My problem was I needed to specify the full annotation. It required the nginx prefix

nginx.ingress.kubernetes.io/affinity:             cookie
nginx.ingress.kubernetes.io/session-cookie-hash:  sha1
nginx.ingress.kubernetes.io/session-cookie-name:  route
-- Rick Baker
Source: StackOverflow