问题描述
如果您在 Openshift3 中扩展 Pod,来自同一客户端 IP 地址的所有请求都将发送到与会话关联的容器.
If you scale up a Pod in Openshift3, all requests coming from the same client IP address are sent to container which has the session associated.
是否有任何配置可以禁用粘性会话?如何在 Openshift 中管理内部 HAProxy 的选项?
Is there any configuration to disable sticky sessions? How can I manage the options of internal HAProxy in Openshift?
推荐答案
为了后代,由于我有同样的问题,我想记录我使用的解决方案 Graham Dumpleton 的精彩评论.
For posterity, and since I had the same problem, I want to document the solution I used from Graham Dumpleton's excellent comment.
事实证明,在第一个请求期间设置了一个 cookie,它将后续请求重定向到同一后端.要在每个路由的基础上禁用此行为:
As it turns out, a cookie is set during the first request that redirects subsequent requests to the same back-end. To disable this behavior on a per-route basis:
oc annotate routes myroute haproxy.router.openshift.io/disable_cookies='true'
这可以防止设置 cookie 并允许平衡算法为来自同一客户端的后续请求选择适当的后端.更改余额算法:
This prevents the cookie from being set and allows the balance algorithm to select the appropriate back-end for subsequent requests from the same client. To change the balance algorithm:
oc annotate routes myroute haproxy.router.openshift.io/balance='roundrobin'
通过设置这两个注解,来自同一个客户端 IP 地址的请求会依次发送到每个后端,而不是一遍又一遍地发送到同一个后端.
With these two annotations set, requests from the same client IP address are sent to each back-end in turn, instead of the same back-end over and over.
这篇关于如何在 Openshift3 中禁用粘性会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!