Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling sticky sessions with nginx ingress, not working

Tags:

kubernetes

I have a v1.8.4 deployment running nginx ingress controller. I had an ingress which works fine. But now I am trying to enable sticky sessions in it. I used kubectl edit ing mying to add these annotations:

nginx.ingress.kubernetes.io/affinity: cookie
nginx.ingress.kubernetes.io/session-cookie-hash: md5
nginx.ingress.kubernetes.io/session-cookie-name: foobar

But sticky sessions are still not working. Nginx config does not have anything about sticky sessions. Also, kubectl describe ing mying does not show the annotations. What is going wrong here?

I also tried the example for sticky sessions here. Describing the ingress does not show the annotations.

like image 529
Abhishek Chanda Avatar asked Oct 18 '22 00:10

Abhishek Chanda


1 Answers

Because item host(in ingress.yml) cannot be empty or wildzard (*.example.com).

Make sure your host such as test.example.com(if u don't have dns, please config it in your local hosts),then test

curl -I  http://test.example.com/test/login.jsp

then u will see

Set-Cookie: route=ebfcc90982e244d1d7ce029b98f8786b; Expires=Sat, 03-Jan-70 00:00:00 GMT; Max-Age=172800; Domain=test.example.com; Path=/test; HttpOnly

The official example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-test
  annotations:
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"

spec:
  rules:
  - host: stickyingress.example.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /
like image 156
mumubin Avatar answered Oct 20 '22 22:10

mumubin