我正在尝试路由一个与nginxingress的api共存的应用程序。我的nginx入口控制器是:
-------------------------------------------------------------------------------
NGINX Ingress controller
Release: v0.41.2
Build: d8a93551e6e5798fc4af3eb910cef62ecddc8938
Repository: https://github.com/kubernetes/ingress-nginx
nginx version: nginx/1.19.4
-------------------------------------------------------------------------------
kubectl describe service -n ingress-nginx ingress-nginx-controller
Name: ingress-nginx-controller
Namespace: ingress-nginx
Selector: app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/name=ingress-nginx
Type: NodePort
IP: 10.233.38.239
Port: http 80/TCP
NodePort: http 30851/TCP
[... blabla...]
我有两个部署(API(与java和(TSP(一个有角度的APP,我在这个ingress-resource:中引用了它们
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: simple-fanout-example
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/rewrite-target: /$2
ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: "*.example.com"
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: sit-api
port:
number: 8080
- path: /tsp/(/|$)(.*)
pathType: Prefix
backend:
service:
name: sit-web
port:
number: 8080
如果我描述入口->
Rules:
Host Path Backends
---- ---- --------
*.example.com
/api sit-api:8080 10.233.90.13:8080,10.233.96.34:8080)
/tsp/(/|$)(.*) sit-web:8080 10.233.92.13:80,10.233.96.36:80)
这里一切都很好,/api正在正常工作。但每当我试图从/tsp中取出任何东西时,我都会得到404:
curl -I ctrlnginx.example.com:30851/tsp
HTTP/1.1 404 Not Found
----
curl ctrlnginx.example.com:30851/api
{"200":"OK","message":"No message available","path":"/api"}
我是不是错过了什么?
有一个愚蠢的打字错误。。。很抱歉答复迟了。与- path: /tsp/(/|$)(.*)
具有atrailing"/"必须移除。仅供参考:入口通告适用于入口内的所有路径。因此,如果您需要为每条路径创建不同的入口,请为每条不同的路径创建一个入口:(谢谢大家!