Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to allow sticky sessions per location #871

Merged
merged 1 commit into from
Jun 23, 2017

Conversation

aledbf
Copy link
Member

@aledbf aledbf commented Jun 16, 2017

This PR enables sticky session per location inside a server
Also avoids reusing the same upstream block when sticky sessions is not configured

kubectl create -f https://github.com/raw/kubernetes/ingress/master/examples/http-svc.yaml
echo "
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/affinity: cookie
    ingress.kubernetes.io/session-cookie-hash: sha1
    ingress.kubernetes.io/session-cookie-name: route
  name: nginx-test
  namespace: default
spec:
  rules:
  - host: sticky-ingress.example.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-test-ns
  namespace: default
spec:
  rules:
  - host: no-sticky-ingress.example.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-test-ns-path
  namespace: default
spec:
  rules:
  - host: sticky-ingress.example.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        # Add a custom path that use the same service without sticky sessions
        path: /no-sticky-session
" | kubectl create -f -

Check sticky sessions is working:

$ kubectl exec -n kube-system <ingress pod> -- curl -v localhost  -H'Host: sticky-ingress.example.com'

It must appear something like

< Set-Cookie: route=dc89ae303c62a8bfce8bf32f06d27c31f0980ef7; Path=/; HttpOnly

Check a different host with no sticky sessions that uses the same service:

$ kubectl exec -n kube-system <ingress pod> -- curl -v localhost  -H'Host: no-sticky-ingress.example.com'

Now check a different path in the host with sticky sessions where the feature is not enabled:

$ kubectl exec -n kube-system nginx-ingress-controller-3401347994-vjvhv  -it -- curl -v localhost/no-sticky-session  -H'Host: stickyingress.example.com'

fixes #844
fixes #771

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 16, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@aledbf
Copy link
Member Author

aledbf commented Jun 16, 2017

@rikatz ping

@aledbf aledbf force-pushed the fix-sticky branch 2 times, most recently from 6d036d2 to a8d9c8e Compare June 16, 2017 02:48
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 46.673% when pulling a8d9c8eb24c0291a86bc64c6631068a89a0181e2 on aledbf:fix-sticky into c6b5335 on kubernetes:master.

@rikatz
Copy link
Contributor

rikatz commented Jun 19, 2017

@aledbf What happens here if we have multiple ingresses pointing to the same 'host', some with sticky enabled, other with only whitelist enabled?

Is there any conflict here that may happen?

I'll test this probably between today and tomorrow and will provide you a feedback :)

@aledbf aledbf changed the title WIP: Add feature to allow sticky sessions per location Add feature to allow sticky sessions per location Jun 21, 2017
@aledbf
Copy link
Member Author

aledbf commented Jun 21, 2017

Is there any conflict here that may happen?

No.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 44.564% when pulling 83d03a1 on aledbf:fix-sticky into 955897a on kubernetes:master.

@aledbf aledbf merged commit 312c9ec into kubernetes:master Jun 23, 2017
@aledbf aledbf deleted the fix-sticky branch June 25, 2017 21:42
@garyyang85
Copy link

@aledbf I just follow these steps on my env, but I can not see anything like this:
< Set-Cookie: route=dc89ae303c62a8bfce8bf32f06d27c31f0980ef7; Path=/; HttpOnly

after run : kubectl exec -n kube-system -- curl -v localhost -H'Host: sticky-ingress.example.com'

just some output like this:


  • Rebuilt URL to: localhost/
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying ::1...
  • Connected to localhost (::1) port 80 (#0)

GET / HTTP/1.1
Host: sticky-ingress.example.com
User-Agent: curl/7.47.0
Accept: /

< HTTP/1.1 200 OK
< Server: nginx/1.13.3
< Date: Thu, 17 Aug 2017 14:41:57 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
<
{ [679 bytes data]
100 672 0 672 0 0 98k 0 --:--:-- --:--:-- --:--:-- 109k

  • Connection #0 to host localhost left intact

Hostname: http-svc-tzdt8

Pod Information:
node name: k8stest-7
pod name: http-svc-tzdt8
pod namespace: default
pod IP: 10.254.94.7

Server values:
server_version=nginx: 1.13.3 - lua: 10008

Request Information:
client_address=10.254.74.0
method=GET
real path=/
query=
request_version=1.1
request_uri=http://sticky-ingress.example.com:8080/

Request Headers:
accept=/
connection=close
host=sticky-ingress.example.com
user-agent=curl/7.47.0
x-forwarded-for=::1
x-forwarded-host=sticky-ingress.example.com
x-forwarded-port=80
x-forwarded-proto=http
x-original-uri=/
x-real-ip=::1
x-scheme=http

Request Body:
-no body in request-


I am using kubernetes 1.5.7 and nginx 0.9-beta.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. nginx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ingress annotations affinity is not working Sticky Ingress annotations don't appear to work at all
6 participants