【发布时间】:2022-01-08 23:09:27
【问题描述】:
我有一个 haproxy 作为在 k8s 中运行的负载均衡器,并有一条通往具有两个正在运行的 pod 的服务的路由。我希望 haproxy 中的服务器命名与我的服务背后的 pod 名称相对应。如果我没记错的话,下面的 configmap / annotation 值应该这样做:https://haproxy-ingress.github.io/docs/configuration/keys/#backend-server-naming。但对我来说它没有,对于我的生活,我无法找出原因。我的配置的相关部分如下所示:
控制器部署:
kind: Deployment
metadata:
labels:
run: haproxy-ingress
name: haproxy-ingress
namespace: haproxy-controller
spec:
replicas: 2
selector:
matchLabels:
run: haproxy-ingress
template:
metadata:
labels:
run: haproxy-ingress
spec:
serviceAccountName: haproxy-ingress-service-account
containers:
- name: haproxy-ingress
image: haproxytech/kubernetes-ingress
args:
- --configmap=haproxy-controller/haproxy-ingress
- --configmap-errorfiles=haproxy-controller/errorfile-conf
- --default-ssl-certificate=haproxy-controller/haproxy-tls
- --ingress.class=haproxy
控制器服务:
kind: Service
metadata:
labels:
run: haproxy-ingress
name: haproxy-ingress
namespace: haproxy-controller
spec:
selector:
run: haproxy-ingress
type: ClusterIP
ports:
- name: https
port: 443
protocol: TCP
targetPort: 443
控制器配置图:
kind: ConfigMap
metadata:
name: haproxy-ingress
namespace: haproxy-controller
data:
server-ssl: "true"
scale-server-slots: "2"
cookie-persistence: "LFR_SRV"
backend-server-naming: "pod"
backend-config-snippet: |
cookie LFR_SRV indirect nocache insert maxidle 10m httponly secure
后端服务器入口:
kind: Ingress
metadata:
name: liferay-dxp
namespace: backend
annotations:
kubernetes.io/ingress.class: "haproxy"
spec:
tls:
- secretName: backend-tls
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: backend
port:
number: 443
haproxy.conf 生成的后端部分如下所示:
mode http
balance roundrobin
option forwardfor
cookie LFR_SRV indirect nocache insert
###_config-snippet_### BEGIN
cookie LFR_SRV indirect nocache insert maxidle 10m httponly secure
###_config-snippet_### END
server SRV_1 10.xx.xx.xx:443 check ssl alpn h2,http/1.1 weight 128 cookie SRV_1 verify none
server SRV_2 10.xx.xx.xx:443 check ssl alpn h2,http/1.1 weight 128 cookie SRV_2 verify none
除了backend-server-naming: "pod",一切正常。我也无法从here 获得任何 session-cookie-* 属性来工作。因此,我使用backend-config-snippet 用我的自定义设置覆盖生成的haproxy.conf 中的cookie 行(我添加了maxidle 10m httponly secure)。我做错了什么?
【问题讨论】:
-
使用哪个kubernetes版本?是云端还是本地?
-
Kubernetes 版本:v1.19.13-eks-8df270(AWS 云)
标签: kubernetes cookies haproxy haproxy-ingress