我有一个have作为一个负载均衡器在k8s中运行,它有一个路由到一个具有两个正在运行的豆荚的服务。我希望在haproxy中命名的服务器与我的服务后面的吊舱名称相对应。如果我没有弄错的话,下面的configmap /注释值应该就是这样做的: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控制器configmap:
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",一切都很好。我也无法从这里获得任何会话-cookie-*属性。因此,我使用backend-config-snippet用自定义haproxy.conf覆盖生成的haproxy.conf中的cookie行(我添加了maxidle 10m httponly secure)。我做错了什么?
发布于 2021-12-06 17:07:44
以下是一些帮助你解决问题的提示。
一定要知道您的haproxy ingress控制器的确切版本:
查看您共享的清单文件,很难判断您正在集群中运行的haproxy-ingress-controller容器的确切版本(顺便说一句,这违背了生产env中的最佳实践,即离开它的w/o标记,阅读更多关于它的这里)。
要使backend-server-naming配置键正常工作,最低限度需要使用v0.8.1。
在继续进行故障排除之前,请首先检查您的入口部署是否兼容。
我对“后端服务器命名=荚”行为的观察
配置动态更新:
如果我正确理解这个配置键上的正式文档,将服务器后端命名为荚name (backend-server-naming=pod)而不是sequences,则确实支持haproxy配置的动态重新加载,但到目前为止不支持对后端部分的haproxy运行时配置进行动态更新(haproxy ingress 这里和这里解释了这一点)。
这意味着您需要首先重新启动haproxy ingress控制器实例,以便能够看到在haproxy配置中反映的后端服务器名称的更改,例如,当新的Pod副本出现或POD_IP由于Pod崩溃而更改时(期望基于顺序命名的服务器条目的添加/更新)。
进境阶级:
我已经成功地测试了backend-server-naming=pod设置(参见下面的测试),该设置基于ingressClassName字段,而不是不推荐的注释kubernetes.io/ingress.class,就像在您的例子中那样:
我并不是说您的配置不起作用(也应该是这样),但重要的是要知道,配置的动态更新(这包括后端信任的更改)不会发生在非机密的入侵资源上,也不会出现错误分类的配置,除非您真的在运行v0.12或更新版本。
测试:
# Ingress class
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: my-class
annotations:
ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: haproxy-ingress.github.io/controller
# Demo Ingress resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
haproxy-ingress.github.io/backend-server-naming: "pod"
name: echoserver
spec:
ingressClassName: my-class
rules:
- http:
paths:
- backend:
service:
name: echoserver
port:
number: 8080
path: /
pathType: Prefix带有注释的HA代理配置:
backend default_echoserver_8080
mode http
balance roundrobin
acl https-request ssl_fc
http-request set-header X-Original-Forwarded-For %[hdr(x-forwarded-for)] if { hdr(x-forwarded-for) -m found }
http-request del-header x-forwarded-for
option forwardfor
http-response set-header Strict-Transport-Security "max-age=15768000" if https-request
# pod name start
server echoserver-75d6f584bb-jlwb8 172.17.0.2:8080 weight 1 check inter 2s
# pod name end
server srv002 127.0.0.1:1023 disabled weight 1 check inter 2s
server srv003 127.0.0.1:1023 disabled weight 1 check inter 2s
server srv004 127.0.0.1:1023 disabled weight 1 check inter 2s
...https://stackoverflow.com/questions/70199796
复制相似问题