我正在尝试在K8S集群内部使用HAProxy实现一些基于cookie的 session 粘性。我正在使用2.0.2- Alpine 图像。
在这种环境中,我有10个虚拟虚拟应用程序StatefulSet的Pod(全部处于 Activity 状态并准备就绪),并且HAProxy通过以下后端指向其服务:
backend within_session
log global
mode http
option log-health-checks
option httpchk GET /isalive
balance roundrobin
dynamic-cookie-key XXXXX
cookie SESSION_COOKIE rewrite nocache dynamic
option httpclose
server-template srv 10 _http._tcp.dummywebapplication-service.mynamespace.svc.cluster.local resolvers k8s check
尽管我将“srv”设置为最多10个,并且有10个Pod正在运行,但是HAProxy仅创建了4个“srv”。
是否知道会导致什么?
以下是相关的HAProxy日志:
<133>Jul 23 08:09:04 haproxy[7]: within_session/srv1 changed its FQDN from (null) to dummywebapplication-0.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:09:54 haproxy[7]: within_session/srv2 changed its FQDN from (null) to dummywebapplication-1.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:10:24 haproxy[7]: within_session/srv3 changed its FQDN from (null) to dummywebapplication-2.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:11:14 haproxy[7]: within_session/srv4 changed its FQDN from (null) to dummywebapplication-3.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:11:54 haproxy[7]: within_session/srv3 changed its FQDN from (null) to dummywebapplication-4.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:13:14 haproxy[7]: within_session/srv2 changed its FQDN from (null) to dummywebapplication-6.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:14:44 haproxy[7]: within_session/srv2 changed its FQDN from (null) to dummywebapplication-8.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:20:04 haproxy[7]: within_session/srv1 changed its FQDN from (null) to dummywebapplication-6.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:20:04 haproxy[7]: within_session/srv2 changed its FQDN from (null) to dummywebapplication-1.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
<133>Jul 23 08:20:04 haproxy[7]: within_session/srv3 changed its FQDN from (null) to dummywebapplication-5.dummywebapplication-service.mynamespace.svc.cluster.local by 'SRV record'
考虑前4行具有srv1-4,之后再使用了srv id。
最佳答案
将accepted_payload_size 8192
添加到“左轮手枪”即可解决该问题。
关于kubernetes - HAProxy 2.0.2不会为服务中的所有Pod创建 'srv',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57148351/