【问题标题】:I want to access dynamic value in VirtualService for uri我想在 VirtualService 中为 uri 访问动态值
【发布时间】:2020-05-17 07:38:33
【问题描述】:

我想部署两个具有不同 URL 的服务。

 - match:
      uri:
        prefix: /pune
    route:
    - destination:
        host: wagholi
        port:
          number: 8080
 - match:
      uri:
        prefix: /pune/{location}
    route:
    - destination:
        host: yerwada
        port:
          number: 8080
 - match:              
      uri:
        prefix: /pune/{local}/here
    route:
    - destination:
        host: hadapsar
        port:
          number: 8080

在这种情况下,当我将位置值作为 yerwada 传递时,当我点击 API 得到 404 Not Found /pune/yerwada 时。此外,当我在本地通过 hadapsar 时,我正在传递 /pune/hadapsar/here 得到相同的错误 404 Not Found /pune/hadapsar/here。 !!!!!!

【问题讨论】:

    标签: kubernetes routing kubernetes-ingress istio gateway


    【解决方案1】:

    我们可以为 uri 使用正则表达式。

     - match:
          uri:
            prefix: /pune
        route:
        - destination:
            host: wagholi
            port:
              number: 8080
     - match:
          uri:
            regex: \/pune/\/(.+)
        route:
        - destination:
            host: yerwada
            port:
              number: 8080
     - match:              
          uri:
            prefix: \/pune\/(.+)\/here
        route:
        - destination:
            host: hadapsar
            port:
              number: 8080
    

    【讨论】:

      【解决方案2】:

      请求是否传入名为location 且值为pune 的标头?如果“否”,则从匹配规则中删除它 - 这是请求不被 uri 前缀单独匹配的原因:

          - headers:
              location:
                exact: pune
      

      以防万一,这里是relevant doc的链接。

      【讨论】:

      • 更新了问题。
      猜你喜欢
      • 2020-05-30
      • 2021-11-28
      • 2021-12-29
      • 1970-01-01
      • 2020-10-28
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      相关资源
      最近更新 更多