我有两个应用程序(工作负载(:app1
和app2
。如果有diona
前缀,我的目标是将trafic从app1
重定向到app2
。例如:
app1/diona > app2/<api>
现在我有这样的规则:
rules:
- host: host
http:
paths:
- backend:
serviceName: ingress-37ce1ad1e8214375784d1e50805c056c
servicePort: 80
path: /diona
当我在app2
的日志中检查app1/diona
端点时,出现了一个错误:
Not Found: /diona
如何在不实现app2
中的diona
前缀的情况下正确重定向trafic?
您可以使用nginx入口控制器来实现它。你的代码看起来像这个
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: rewrite
spec:
rules:
- host: host
http:
paths:
- backend:
serviceName: ingress-37ce1ad1e8214375784d1e50805c056c
servicePort: 80
path: /diona
如果要将app1/diona/*
重定向到app2/*
,请将注释更改为
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: rewrite
spec:
rules:
- host: host
http:
paths:
- backend:
serviceName: ingress-37ce1ad1e8214375784d1e50805c056c
servicePort: 80
path: /diona/(.*)
参考