TL;DR: I can't get session affinity in Kubernetes work using the official nginx ingress helm chart. I've tried these instructions:
Sticky Sessions – nginx ingress controller
Using Session Affinity on Kubernetes
I've also tried to read up on the service handling. However, I get no effect whatsoever, with requests being pointed to my back end service and then load balanced by its headless service.
More information on my case:
I have a public API running with three pods in Kubernetes, with an nginx ingress in front of it. The cluster is on AWS and set up using Kops.
For a third-party user, I've set up digest auth to be able to return some sensitive data. I've used a fork of this digest auth package.
All fine and dandy, works swell in dev.
However, after I deploy my system, giving it three stateless pods, the first digest request will end up on one pod, and the client's response will end up on another pod, breaking the functionality.
What is it I'm missing? All I want is that a client's IP address will always have its request ending up on a single pod in my deployment.
Thanks!
Best Answer
I found the answer, and whaddyaknow! It was my own fault, of course.
The problem was that I tried to configure the nginx ingress chart, which was not the way to go. The nginx ingress only provides the functionality - the services you run yourself provide the requested behaviour.
In my own service that I had deployed, I had an
ingress
-statement. Adding the annotation for cookies there solved my issue.Also, creds to Nepomucen for informing me in the comments that the
cookie
affinity would work even though it's a bot user.Here's my full helm chart for my own service that relied on the nginx ingress: