我想在Ingress规则的路径中使用正则表达式,但我无法让它工作. For example:
apiVersion: extensions/v1beta1
kind: Ingress
Metadata:
name: cafe-ingress
spec:
tls:
- hosts:
- cafe.example.com
secretName: cafe-secret
rules:
- host: cafe.example.com
http:
paths:
- path: /tea
backend:
serviceName: tea-svc
servicePort: 80
- path: /coffee
backend:
serviceName: coffee-svc
servicePort: 80
我尝试将/ t [a-z] a放在第一条路径上,但是我尝试的任何路径应该匹配该正则表达式,这使我进入默认后端而不是我期望的服务.
最佳答案
注意:它看起来不再适用.
原文链接:https://www.f2er.com/nginx/434298.html似乎解决方案非常简单(至少使用Nginx入口控制器) – 您只需要在路径前加上“〜”:
apiVersion: extensions/v1beta1
kind: Ingress
Metadata:
name: cafe-ingress
spec:
tls:
- hosts:
- cafe.example.com
secretName: cafe-secret
rules:
- host: cafe.example.com
http:
paths:
- path: ~ /t[a-z]a
backend:
serviceName: tea-svc
servicePort: 80
- path: /coffee
backend:
serviceName: coffee-svc
servicePort: 80