入口在请求上调用随机服务,也调用根(/(。我需要入口来调用配置服务中指定的并将完整路径发送到服务(我使用 MVC 模式,因此我需要为应用程序提供完整路径以解析正确的控制器(
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: whatever
annotations:
ingress.kubernetes.io/add-base-url: "true"
ingress.kubernetes.io/rewrite-target: "/"
kubernetes.io/ingress.class: "gce"
kubernetes.io/ingress.global-static-ip-name: "my-static-ip-name"
spec:
tls:
- secretName: my-tls-secret
hosts:
- whatever.my-awesome-project.com
rules:
- host: whatever.my-awesome-project.com
http:
paths:
- path: /api/whatever
backend:
serviceName: whatever-service
servicePort: 80
- path: /api/not-whatever
backend:
serviceName: not-whatever-service
servicePort: 80
- path: /images/*
backend:
serviceName: not-whatever-service
servicePort: 80
从我在你问题中看到的:
1(您正在尝试将rewrite-target
与gce
入口一起使用-->这不起作用。Rewrite-Target 是 NGINX 入口控制器的功能。顺便说一句,从 0.22.0 版本开始,您应该使用 nginx.ingress.kubernetes.io/rewrite-target: "/"
而不是ingress.kubernetes.io/rewrite-target: "/"
2(注释添加库网址已在 0.22.0 中删除。这也是nginx注释,而不是gce。更多信息在这里和这里。
3(另外,我相信如果您想拥有正确的路径rewrite-target
则不需要注释
从我的战俘中应该有这样的东西:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: whatever
annotations:
kubernetes.io/ingress.class: "nginx"
kubernetes.io/ingress.global-static-ip-name: "my-static-ip-name"
spec:
tls:
- secretName: my-tls-secret
hosts:
- whatever.my-awesome-project.com
rules:
- host: whatever.my-awesome-project.com
http:
paths:
- path: /api/whatever
backend:
serviceName: whatever-service
servicePort: 80
- path: /api/not-whatever
backend:
serviceName: not-whatever-service
servicePort: 80
- path: /images/*
backend:
serviceName: not-whatever-service
servicePort: 80
很多事情取决于您使用的入口和版本。你有可能搬到nginx吗?