基于标题用户代理的Istio RouteRule不起作用 [英] Istio RouteRule based on headers user-agent doesn't work
问题描述
我在minikube上运行了两个服务,Foo
和Bar
.当我访问Foo
服务时,它向Bar
服务发出请求以检索一些数据. Bar
服务具有2个版本"1.0"
和"2.0"
.
我已经使用istio
设置了默认的RouteRule
配置,以将所有请求路由到"1.0"
:
I have two services running on minikube, Foo
and Bar
. When I'm accessing the Foo
service it makes a request to Bar
service to retrieve some data. Bar
service have 2 versions "1.0"
and "2.0"
.
I have setup the default RouteRule
configuration with istio
to route all the requests to "1.0"
:
apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
name: bar-default
spec:
destination:
name: bar-server
precedence: 1
route:
- labels:
version: "1.0"
它工作正常,我可以看到所有请求都转发到了"1.0"
.
现在,我想基于标题添加另一个RouteRule
,因此来自Chrome
浏览器的所有请求都将转发到"2.0"
:
It works fine, and I can see that all the requests is forwarded to "1.0"
.
Now I want to add another RouteRule
based on the headers, so all the requests from Chrome
browser will be forwarded to "2.0"
:
apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
name: bar-v2
spec:
destination:
name: bar-server
precedence: 2
match:
request:
headers:
user-agent:
regex: ".*Chrome.*"
route:
- labels:
version: "2.0"
它不起作用.所有请求仍路由到"1.0"
.
我可以看到RouteRule
已创建:
And it doesn't work. All the requests are still routed to "1.0"
.
I can see that the RouteRule
is created:
> istioctl get routerules
NAME KIND NAMESPACE
bar-default RouteRule.v1alpha2.config.istio.io default
bar-v2 RouteRule.v1alpha2.config.istio.io default
我可以在浏览器的开发人员工具中看到UserAgent
标头存在.
如何调试请求以查看为什么不转发给"2.0"
?
I can see in the developers tools in browser that the UserAgent
header is present.
How can I debug the request to see why doesn't it get forwarded to "2.0"
?
推荐答案
您的Foo服务可能没有传递从浏览器获取的User-Agent标头.
It could be that your Foo service does not pass the User-Agent header that it gets from the browser.
其他检查将是通过kubectl exec
从Foo对Bar执行curl
调用,并在将其传递给User-Agent标头时检查版本2.0是否被调用:
Additional check would be to perform a curl
call to Bar from Foo by kubectl exec
and to check that version 2.0 is called when passing it the User-Agent header:
curl -H "user-agent: ---Chrome---" bar-server
您可以将curl
安装在Foo容器中,或者将单独的容器与curl
一起使用,例如
You can either install curl
in your Foo container, or use a separate container with curl
, like this one from Istio samples
这篇关于基于标题用户代理的Istio RouteRule不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!