使用Nginx入口启用粘性会话,但不起作用 [英] Enabling sticky sessions with nginx ingress, not working

查看:409
本文介绍了使用Nginx入口启用粘性会话,但不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行nginx入口控制器的v1.8.4部署.我有一个可以正常工作的入口.但是现在我正在尝试在其中启用粘性会话.我用kubectl edit ing mying添加了这些注释:

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

但是粘性会话仍然无法正常工作. Nginx配置没有关于粘性会话的任何信息.另外,kubectl describe ing mying不显示注释.这里出了什么问题?

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.

推荐答案

因为项目host(在ingress.yml中)不能为空或wildzard(* .example.com).

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

确保您的主机(例如test.example.com)(如果您没有dns,请在本地主机中对其进行配置),然后进行测试

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

然后你会看到

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

官方示例:

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: /

这篇关于使用Nginx入口启用粘性会话,但不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆