istio:VirtualService 重写到根 url

Joe*_*e J 4 routing kubernetes istio envoyproxy

我有一个 Istio 1.4.6 VirtualService,它有一个匹配项和一个 url 重写,定义如下:

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

Run Code Online (Sandbox Code Playgroud)

我想重写如下:

指向的流量/foo/bar或其任何子路径都应重写为/加上 上的任何子路径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
Run Code Online (Sandbox Code Playgroud)

但是,当我对进入的流量进行 sysdig 时some-service,我看到 Istio 已将路径重写为:

GET //subpath/anothersubpath HTTP/1.1
Run Code Online (Sandbox Code Playgroud)

请注意 GET 请求中的两个斜杠。在 VirtualService 规范rewrite.uri字段中,我似乎无法将该字段留空或在其中添加空字符串。这样做会导致资源无法验证。

即我不能这样做:

    rewrite:
      uri: ""
Run Code Online (Sandbox Code Playgroud)

并且不能这样做

    rewrite:
      uri:
Run Code Online (Sandbox Code Playgroud)

如何定义 VirtualService 重写以将流量发送到目标服务的根?任何帮助深表感谢。

Hit*_*nds 15

另一种方法是:

    - match:
        - uri:
            prefix: "/v2/my-service/"
        - uri:
            exact: "/v2/my-service"
      rewrite:
        uri: "/"
      route:
        - destination:
            host: my-internal-service
            port:
              number: 6666
Run Code Online (Sandbox Code Playgroud)


Pio*_*lec 7

有一个关于这个的github问题

最简单的解决方法是在uri您没有运行.net核心应用程序时添加空格。

    rewrite:
      uri: " "
Run Code Online (Sandbox Code Playgroud)

其他解决方法可以在这里找到,

希望能帮助到你。