我通过添加一个新路径更新了我的ingress.yaml,例如,我添加了example.com/dev/。我删除了旧的ingress并部署了新的ingress,但我的应用程序仍然被重定向到旧的example.com,并在访问example.com/dev/I时获得"在此服务器上找不到请求的资源"我使用相同的旧tls证书,因为主机名仍然是example.com。当我描述我的入口时,我得到:
Name: example-ingress
Namespace: dev-env
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
selfsigned-cert terminates example.com
Rules:
Host Path Backends
---- ---- --------
example.com
/dev/static app-svc:80 (172.16.0.29:80)
/dev/(.*) app-svc:8000 (172.16.0.29:8000)
Annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: 20m
nginx.ingress.kubernetes.io/rewrite-target: /$1
Events: <none>
我的入口文件是:
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: example-ingress
namespace: prod-env
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- example.com
secretName: selfsigned-cert
rules:
- host: example.com
http:
paths:
- path: /dev/static
backend:
serviceName: app-svc
servicePort: 80
- path: /dev/(.*)
backend:
serviceName: app-svc
servicePort: 8000
status:
loadBalancer:
ingress:
- ip: 192.168.0.19
hostname: example.com
请为两种服务应用8000或80的相同端口:
- host: example.com
http:
paths:
- path: /dev/static
backend:
serviceName: app-svc
servicePort: 8000
- path: /dev/(.*)
backend:
serviceName: app-svc
servicePort: 8000
或
- host: example.com
http:
paths:
- path: /dev/static
backend:
serviceName: app-svc
servicePort: 80
- path: /dev/(.*)
backend:
serviceName: app-svc
servicePort: 80
同时尝试将注释更改为:nginx.ingress.kubernetes.io/rewrite-target: $2
看看:入口路径,入口重写目标。