在 Kubernetes 中,如何使用 Ingress 实现会话亲和性?
In Kubernetes, how do I implement session affinity using an Ingress?
我想实现一个粘性会话 Ingress 控制器。 Cookie 或 IP 哈希都可以;只要同一个客户端 通常 路由到同一个 pod,我就很高兴。
我坚持的是:似乎 Kubernetes 服务模型意味着我的连接无论如何都会被随机代理。我可以使用会话亲和力配置我的 Ingress 控制器,但是一旦连接通过并命中服务,kube-proxy
就会随机路由我。服务上有 sessionAffinity: ClientIP
标志,但这对我没有帮助——客户端 IP 将始终是 Ingress pod 的内部 IP。
我错过了什么吗?鉴于 Kubernetes 当前的架构,这可能吗?
入口控制器可以完全绕过 kube-proxy。 haproxy 控制器,例如 does this and goes straight to endpoints. However it doesn't use the Ingress in the typical sense。
您可以do the same with the nginx controller, all you need to lookup endpoints and insert them instead of the DNS name it currently uses (i.e swap this line 获取指向包含端点的上游的指针。
我评估了 haproxy 控制器,但无法通过会话亲和性可靠地获得它 运行。经过一些研究,我发现 Nginx Ingress Controller which since version 0.61 also includes the nginx-sticky-module-ng module and is now running reliably since a couple of days in our test environment. I created a Gist 设置了所需的 Kubernetes 部分,因为一些重要的配置很难在现有文档中找到。祝你好运!
我想实现一个粘性会话 Ingress 控制器。 Cookie 或 IP 哈希都可以;只要同一个客户端 通常 路由到同一个 pod,我就很高兴。
我坚持的是:似乎 Kubernetes 服务模型意味着我的连接无论如何都会被随机代理。我可以使用会话亲和力配置我的 Ingress 控制器,但是一旦连接通过并命中服务,kube-proxy
就会随机路由我。服务上有 sessionAffinity: ClientIP
标志,但这对我没有帮助——客户端 IP 将始终是 Ingress pod 的内部 IP。
我错过了什么吗?鉴于 Kubernetes 当前的架构,这可能吗?
入口控制器可以完全绕过 kube-proxy。 haproxy 控制器,例如 does this and goes straight to endpoints. However it doesn't use the Ingress in the typical sense。
您可以do the same with the nginx controller, all you need to lookup endpoints and insert them instead of the DNS name it currently uses (i.e swap this line 获取指向包含端点的上游的指针。
我评估了 haproxy 控制器,但无法通过会话亲和性可靠地获得它 运行。经过一些研究,我发现 Nginx Ingress Controller which since version 0.61 also includes the nginx-sticky-module-ng module and is now running reliably since a couple of days in our test environment. I created a Gist 设置了所需的 Kubernetes 部分,因为一些重要的配置很难在现有文档中找到。祝你好运!