Kubernetes Nginx 入口控制器缺少路径
Kubernetes Nginx Ingress Controller missing path
我对 Nginx Ingress Controller 有两个定义。他们每个人都路由到网络应用程序(在 nginx 上托管的 React 应用程序)和网络服务 api(.Net Core)。
首先可以正常工作,但是很麻烦,因为我需要在 etc 文件中为每个指定的主机添加条目以使其工作:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx-controller
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: testapp-web-dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: testapp-portal-web-service
port:
number: 80
- host: testapp-api-dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: testapp-portal-api-service
port:
number: 80
我决定将其修改为具有多个路径的单个主机,因此我将在 etc 文件中只有一个条目。但它不起作用。第一个请求被正确路由到 http://testapp//testapp-web-dev 但每隔一个
请求失败,即清单请求转到 http://testapp/manifest.json 但它应该转到 http://testapp/testapp-web-dev/manifest.json.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx-controller
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: testapp
http:
paths:
- path: /testapp-web-dev(/|$)(.*)
pathType: Prefix
backend:
service:
name: testapp-portal-web-service
port:
number: 80
- path: /testapp-api-dev(/|$)(.*)
pathType: Prefix
backend:
service:
name: testapp-portal-api-service
port:
number: 80
尝试了不同的 url 重写但没有成功。
如果要保留请求的路径,需要删除nginx.ingress.kubernetes.io/rewrite-target: /
注释。
In this ingress definition, any characters captured by (.*)
will be
assigned to the placeholder </code>, which is then used as a parameter in
the rewrite-target annotation.</p>
</blockquote>
<p>即注释将 <code>http://testapp/testapp-web-dev/manifest.json
重定向到 http://testapp/manifest.json
。
我对 Nginx Ingress Controller 有两个定义。他们每个人都路由到网络应用程序(在 nginx 上托管的 React 应用程序)和网络服务 api(.Net Core)。
首先可以正常工作,但是很麻烦,因为我需要在 etc 文件中为每个指定的主机添加条目以使其工作:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx-controller
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: testapp-web-dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: testapp-portal-web-service
port:
number: 80
- host: testapp-api-dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: testapp-portal-api-service
port:
number: 80
我决定将其修改为具有多个路径的单个主机,因此我将在 etc 文件中只有一个条目。但它不起作用。第一个请求被正确路由到 http://testapp//testapp-web-dev 但每隔一个 请求失败,即清单请求转到 http://testapp/manifest.json 但它应该转到 http://testapp/testapp-web-dev/manifest.json.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx-controller
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: testapp
http:
paths:
- path: /testapp-web-dev(/|$)(.*)
pathType: Prefix
backend:
service:
name: testapp-portal-web-service
port:
number: 80
- path: /testapp-api-dev(/|$)(.*)
pathType: Prefix
backend:
service:
name: testapp-portal-api-service
port:
number: 80
尝试了不同的 url 重写但没有成功。
如果要保留请求的路径,需要删除nginx.ingress.kubernetes.io/rewrite-target: /
注释。
In this ingress definition, any characters captured by
(.*)
will be assigned to the placeholder</code>, which is then used as a parameter in the rewrite-target annotation.</p> </blockquote> <p>即注释将 <code>http://testapp/testapp-web-dev/manifest.json
重定向到http://testapp/manifest.json
。