istio: VirtualService rewrite to the root url

↘锁芯ラ 提交于 2021-01-04 17:03:52

问题


I have an Istio 1.4.6 VirtualService with a match and a url rewrite defined as follows:

    match:
    - authority:
        prefix: example.com
      uri:
        prefix: /foo/bar
    rewrite:
      uri: /
    route:
    - destination:
        host: some-service
        port:
          number: 80

I would like a rewrite like follows:

Traffic directed to /foo/bar or any subpath of that should be rewritten to / plus any subpath on some-service.

i.e.
example.com/foo/bar -> some-service
example.com/foo/bar/subpath -> some-service/subpath
example.com/foo/bar/subpath/anothersubpath -> some-service/subpath/anothersubpath

However, when I sysdig the traffic coming into some-service, I see that Istio has rewritten the path to:

GET //subpath/anothersubpath HTTP/1.1

Notice the two slashes in the GET request. In the VirtualService spec rewrite.uri field, I can't seem to leave that field empty or add an empty string there. Doing so causes the resource not to validate.

I.e. I can NOT do this:

    rewrite:
      uri: ""

And can NOT do this

    rewrite:
      uri:

How can I define a VirtualService rewrite to send traffic to the root of the destination service? Any help is much appreciated.


回答1:


There is a github issue about this.

The simplest fix is to add whitespace in the uri as long as You are not running .net core application.

    rewrite:
      uri: " "

Other workaround can be found here,

Hope it helps.




回答2:


I think the right way of doing this is:

    - match:
        - uri:
            prefix: "/v2/my-service/"
        - uri:
            exact: "/v2/my-service"
      rewrite:
        uri: "/"
      route:
        - destination:
            host: my-internal-service
            port:
              number: 6666

It is a matter of order.



来源:https://stackoverflow.com/questions/60658439/istio-virtualservice-rewrite-to-the-root-url

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