首页 > 解决方案 > 带有 Header 的 Istio HTTPMatchRequest 不起作用

问题描述

似乎我的标头匹配被完全忽略了,或者标头在到达使用我的虚拟服务规则对其进行评估的点之前被修改。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-route-rules
spec:
  hosts:
  - mysite.com
  - api.mysite.com
  gateways:
  - istio-system/web-gateway
  - istio-system/api-gateway
  http:
  - match:
    - headers:
        Host: 
          exact: mysite.com
    route:
    - destination:
        host: web.default.svc.cluster.local
        port:
          number: 9000
  - match:
    - headers:
        Host:
          exact: api.mysite.com
    route:
    - destination:
        host: api.default.svc.cluster.local
        port:
          number: 7000

match如果我使用以下规则,我发现路由适用于我的两个服务之一(即使我在单个 下组合时也完全忽略我的标题规则):

...
spec:
  http:
  - match:
    - uri:
        prefix: "/"
...

我认为这表现为“包罗万象”;绝对不是我想要的行为。

尽管一遍又一遍地阅读相关文档,但我担心我严重误解了 Istio 的路由概念)。请帮我弄清楚这里发生了什么。

标签: kubernetesgoogle-kubernetes-engineistio

解决方案


您可以尝试使用特定子集设置DestinationRule 。

您将必须创建一个

kind: DestinationRule

VirtualService而不是用类似的例子来调整你的:

    route:
    - destination:
        host: 
        subset: v2
  - route:
    - destination:
        host: 
        subset: v1

还要记住遵循这些要求,因为在那里很容易出错。

请让我知道这是否有帮助。


推荐阅读