我尝试在k8s中使用haproxy作为负载均衡,使用haproxy-入口作为入口控制器。
我的负载均衡配置:
frontend MyFrontend_80
bind *:80
bind *:443
mode tcp
default_backend TransparentBack_https
backend TransparentBack_https
mode tcp
balance roundrobin
option ssl-hello-chk
server MyWebServer1 10.5.5.53
server MyWebServer2 10.5.5.54
server MyWebServer3 10.5.5.55入口文件:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: li
namespace: li
annotations:
# add an annotation indicating the issuer to use.
cert-manager.io/cluster-issuer: "letsencrypt-staging"
#haproxy.org/forwarded-for: true
kubernetes.io/ingress.class: haproxy
ingress.kubernetes.io/ssl-redirect: "true"
spec:
rules:
- host: a.b.c
http:
paths:
- path: /storage
backend:
serviceName: li-frontend
servicePort: 80
tls:
- hosts:
- a.b.c
secretName: longhorn-ui-tlsli-frontend是一个仪表板ui服务。
当我在入口中将路径字段设置为空白时,一切正常。当path字段设置为/storage或任何非空值时,and page不正常。
我发现一些链接没有得到正确的位置,例如
requst correct value
/main.js /storage/main.js我在nginx-ingress中发现了这个:
#nginx.ingress.kubernetes.io/configuration-snippet: |
#rewrite ^/main(.*)$ /storage/main$1 redirect;haproxy-ingress也有同样的功能吗?我尝试了这些,但没有效果:
ingress.kubernetes.io/app-root: /storage
ingress.kubernetes.io/rewrite-target: /storage此外,我在nginx-ingress中使用了重写,但它在websocket上不起作用。
抱歉,我的台球英语。
发布于 2020-12-18 00:53:12
对于HAProxy:
你必须使用haproxy注解:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: web-ingress
namespace: default
annotations:
# replace all paths with /
haproxy.org/path-rewrite: "/"
# remove the prefix /foo... "/bar?q=1" into "/foo/bar?q=1"
haproxy.org/path-rewrite: (.*) /foo\1
# add the suffix /foo ... "/bar?q=1" into "/bar/foo?q=1"
haproxy.org/path-rewrite: ([^?]*)(\?(.*))? \1/foo\2
# strip /foo ... "/foo/bar?q=1" into "/bar?q=1"
haproxy.org/path-rewrite: /foo/(.*) /\1
spec:
# ingress specification...参考:=> https://www.haproxy.com/documentation/kubernetes/1.4.5/configuration/ingress/
https://stackoverflow.com/questions/62077470
复制相似问题