我的后端运行了三个服务,Ingress路由定义如下:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myapp-ingress
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- hosts:
- myapp.westeurope.cloudapp.azure.com
secretName: acme-crt-secret
rules:
- host: myapp.westeurope.cloudapp.azure.com
http:
paths:
- path: /
backend:
serviceName: myapp-mvc
servicePort: 80
- path: /api
backend:
serviceName: myapp-api
servicePort: 80
- path: /identity
backend:
serviceName: myapp-identity
servicePort: 80
问题是myapp-api已经在监听 /api/v1/myresource
的请求 . 使用当前配置,myapp-api服务仅提供对 myapp.westeurope.cloudapp.azure.com/api/api/v1/myresource
的请求(请注意... / api / api / ...) .
是否可以通过myapp-api服务向 /api
提供请求,但是在不创建另一个Ingress的情况下将这些请求重写为 /
?所以,myapp-api应该为 myapp.westeurope.cloudapp.azure.com/api/v1/myresource
提供服务 .
1 回答
您有两种选择:
a)更改API的端口并使其在该端口上提供服务 .
b)更改您的应用程序,使其在“/ v1 / myresource”上提供API,并通过Ingress为其提供URL的“api”部分 .
无论哪种方式,您都可以在“myapp.westeurope.cloudapp.azure.com/api/v1/myresource”获得资源 .