我对url路径有问题。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: backend
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /v1/$1
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
tls:
- hosts:
- backend.example.com
secretName: backend-example-com
rules:
- host: backend.example.com
http:
paths:
- path: /v9/anonymous/set-data/?(.*)
backend:
serviceName: backend2
servicePort: 80
- path: /v9/?(.*)
backend:
serviceName: backend1
servicePort: 80
在服务中,我得到
/v1/
但是我应该得到
/v1/anonymous/set-data/foo/bar/
我需要重写/v1/
路径中的所有版本一些请求应该去backend1,但一些特定的路径去backend2
找到解决方案
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: backend
annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /v1/$1
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^/v9/?(.*)$ /v1/$1 break;
spec:
tls:
- hosts:
- backend.example.com
secretName: backend-example-com
rules:
- host: backend.example.com
http:
paths:
- path: /v9/anonymous/set-data/?(.*)
backend:
serviceName: backend2
servicePort: 80
- path: /v9/?(.*)
backend:
serviceName: backend1
servicePort: 80
所有内容都重写为/v1/
,并按照工作