在Istio的VirtualService
中,竖线字符似乎不起作用。
下面的示例旨在基于user-agent
头路由请求。来自移动设备的请求应转到myapp
,而来自台式机用户的请求应转到deskt-app
,由下一个匹配块处理。当我使用此正则表达式时,<REGEX>
字段有效:
^.*\bMobile\b.*$
但是要使用这些功能需要更复杂的正则表达式来识别移动用户。当我使用这些时,我的路由完全中断:
^.*\b(iPhone|Pixel)\b.*$
^.*\b(iPhone|Pixel)+\b.*$
^.*\biPhone|Pixel\b.*$
使用带有管道的正则表达式(逻辑或),当我有一个包含单词“ iPhone”或“ Pixel”的myapp
头时,我希望将其路由到user-agent
。
我被路由到deskt-app
。
如何以Istio VirtualService
正则表达式模式实现逻辑或?那是我的问题还是我忽略了一些明显的问题?
VirtualService
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
...
...
http:
- match:
- headers:
user-agent:
regex: "<REGEX>" <------
uri:
prefix: /foo/bar
route:
- destination:
host: myapp
port:
number: 80
- match:
- uri:
prefix: /foo/bar
route:
- destination:
host: deskt-app
port:
number: 80
编辑:Github Issue
答案 0 :(得分:3)
您的配置正确,因此问题必须出在正则表达式上,或者用户代理的内容不同,请尝试尝试'^.*(iPhone|Pixel).*$'
只需验证当标头包含android或iphone时,以下配置即可正确路由:
- match:
- headers:
user-agent:
regex: '^.*(Android|iPhone).*$'
并通过以下测试:
[match] curl -H“用户代理:Mozilla / 5.0(Linux; U; iPhone 4.4.2; zh-cn;)” ...
[无匹配项] curl -H“用户代理:Mozilla / 5.0(Linux; U; Iphne 4.4.2; en-us;)” ...