我的 Ingress 上已经有很多具有如此多路径的域,因为这是一个包含许多微服务的环境。
如何以某种方式编辑我的入口,例如当有人访问路径/servicex
时/serviceb
我当前的入口如下(为简单起见,我省略了其他主机的一些路径)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: main-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/proxy-body-size: "100m"
nginx.ingress.kubernetes.io/max-worker-connections: "0"
nginx.ingress.kubernetes.io/max-worker-open-files: "0"
nginx.ingress.kubernetes.io/client-header-buffer-size: "4k"
spec:
tls:
- hosts:
- subdomain-a.domain.com
- subdomain-b.domain.com
- subdomain-c.domain.com
- subdomain-d.domain.com
- subdomain-e.domain.com
secretName: domain-com-secret
rules:
- host: subdomain-a.domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: default-service
port:
number: 80
- path: /serviceb
pathType: Prefix
backend:
service:
name: b-service
port:
number: 80
- path: /servicec
pathType: Prefix
backend:
service:
name: c-service
port:
number: 80
- path: /serviced
pathType: Prefix
backend:
service:
name: d-service
port:
number: 80
- path: /servicee
pathType: Prefix
backend:
service:
name: e-service
port:
number: 80
- path: /servicee
pathType: Prefix
backend:
service:
name: e-service
port:
number: 80
- path: /servicef
pathType: Prefix
backend:
service:
name: f-service
port:
number: 80
- path: /serviceg
pathType: Prefix
backend:
service:
name: g-service
port:
number: 80
- host: subdomain-b.domain.com
< tons of other rules >
- host: subdomain-c.domain.com
< tons of other rules >
- host: subdomain-d.domain.com
< tons of other rules >
- host: subdomain-e.domain.com
< tons of other rules >
换句话说,/serviceb
如果用户输入以下任何内容,我们希望获得访问权限:
- https://subdomain-a.domain.com/serviceb -> 这里无事可做,因为我们已经涵盖了
- https://subdomain-a.domain.com/servicex -> 这应该转换成https://subdomain-a.domain.com/serviceb
我已经查看了 rewrite 选项,但在我看来,如果我添加注释nginx.ingress.kubernetes.io/rewrite-target: /servicex/$2
,然后尝试执行以下操作:
- path: /serviceb(/|$)(.*)
pathType: Prefix
backend:
service:
name: serviceb
port:
number: 80
不起作用,因为首先,我们已经采用了该路径,其次我认为注释将适用于整个事物,这将损坏所有其他路径。
在此先感谢,任何帮助将不胜感激