Istio RouteRule based on headers user-agent doesn't work

风流意气都作罢 提交于 2019-12-13 04:45:33

问题


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"

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"

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

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"?


回答1:


It could be that your Foo service does not pass the User-Agent header that it gets from the browser.

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

You can either install curl in your Foo container, or use a separate container with curl, like this one from Istio samples



来源:https://stackoverflow.com/questions/48985038/istio-routerule-based-on-headers-user-agent-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!