我想用kubernetes入口工具组织我的web api。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-api-ingress
annotations:
kubernetes.io/ingress.class: nginx
# nginx.ingress.kubernetes.io/use-regex: "true"
# nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: api.myapp.com
http:
paths:
- pathType: Prefix
path: /catalog
backend:
service:
name: myapp-catalog-service
port:
number: 80
- pathType: Prefix
path: /identity
backend:
service:
name: myapp-identity-service
port:
number: 80
通过这个配置,我可以访问"api.myapp.com/catalog
"。
但";api.myapp.com/catalog
";找不到404吗?如何修复这个配置?
似乎是重写注释可能导致404错误的问题。你能在yaml中给出以下注释并尝试一下吗:
nginx.ingress.kubernetes.io/rewrite-target: /$2
根据这个重写目标示例,这些$2占位符可以用作重写目标注释中的参数。此目标URI必须重定向流量。
根据Kubernetes的入口更新你的yaml,如下面的例子,可以从foo.bar.com/foo从端口4200和foo.bar.com/bar从端口8080访问。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: simple-fanout-example
spec:
rules:
- host: foo.bar.com
http:
paths:
- path: /foo
pathType: Prefix
backend:
service:
name: service1
port:
number: 4200
- path: /bar
pathType: Prefix
backend:
service:
name: service2
port:
number: 8080
参考这个入口路径匹配doc和SO