Sticky session for ASP.NET Core on Kubernetes deployment
Found out that I made two logical mistakes:
- Sticky sessions doesn't work this way
I assumed that Kubernetes will look into the cookie and create some mapping of cookie hashes to pods. But instead, another session is generated and append to our http header. nginx.ingress.kubernetes.io/session-cookie-name
is only the name of those generated cookie. So per default, it's not required to change them.
- Scope to the right object
The annotations must be present on the ingress, NOT the deployment (stupid c&p mistake)
apiVersion: extensions/v1beta1kind: Ingressmetadata: name: myapp-k8s-ingress annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/affinity: "cookie" nginx.ingress.kubernetes.io/session-cookie-hash: sha1spec: tls: - hosts: - myapp-k8s.local rules: - host: myapp-k8s.local http: paths: - path: / backend: serviceName: myapp-svc servicePort: 80
This works as expected.