【问题标题】:Are intersecting rules allowed in istio? What is the strategy of applying it?istio 中是否允许交叉规则?应用它的策略是什么?
【发布时间】:2020-05-28 01:18:10
【问题描述】:

假设我有一个 istio 的配置(我使用 GCP):

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-route
  namespace: my-service
spec:
  hosts:
  - "service.cluster.local"
  http:
  - match:
    - headers:
        specific-id:
          regex: ^(1|2|3|4|5)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-01
  - match:
    - headers:
        specific-id:
          regex: ^(6|7|8|9|10)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-02

我的目标规则基于特定的标头(int 值)。

现在我想改变这个配置(因为我需要重新分片),我会有这样的东西:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-route
  namespace: my-service
spec:
  hosts:
 - "service.cluster.local"
  http:
 - match:
    - headers:
        specific-id:
          regex: ^(1|2|3|9|10)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-03
 - match:
    - headers:
        specific-id:
          regex: ^(4|5|6|7|8|)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-04
 - match:
    - headers:
        specific-id:
          regex: ^(1|3|5|7|9|)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-05

我的问题是:

  • istio 规则是否允许在子集中有交集(例如 有一个服务正则表达式:^(1|2|3|4|5)$ 和另一个 ^(1|3|5|7|9|)$)?

  • 使用新规则部署新模式后,当 istio 将 应用它? istio 是否保证它不会被应用(不 删除旧规则)在我的所有新实例都准备好之前 交通?

【问题讨论】:

  • 这些配置有效吗?您使用哪个版本的 istio?
  • @PiotrMalec istio 1.2.4。第一个是我的生产配置,它工作正常。第二个是我想拥有的(我的想法)。我没有用流量测试过。

标签: kubernetes google-cloud-platform istio


【解决方案1】:

istio 规则是否允许在子集中有交集(比如一个服务正则表达式:^(1|2|3|4|5)$ 和另一个 ^(1|3|5|7|9|)$)?

根据istio 文档:

路由规则按从上到下的顺序评估,虚拟服务定义中的第一个规则被赋予最高优先级。在这种情况下,您希望任何与第一条路由规则不匹配的东西都转到第二条规则中指定的默认目的地。因此,第二条规则没有匹配条件,只是将流量导向 v3 子集。

- route:
  - destination:
      host: reviews
      subset: v3

我们建议提供默认的“无条件”或基于权重的规则(如下所述)作为每个虚拟服务中的最后一条规则,以确保流向虚拟服务的流量始终具有至少一个匹配的路由。

按顺序评估路由规则。所以总是会选择第一个匹配项。

regex: ^(1|2|3|9|10)$ 最终会出现在 subset: s-03

regex: ^(4|5|6|7|8|)$ 最终会出现在 subset: s-04

因为regex: ^(1|3|5|7|9|)$ 已经被subset: s-03subset: s-04 覆盖,所以没有匹配项会在subset: s-05 中结束。

请注意,您可以将subset: s-05 设置为“无条件”的默认匹配。


但是您可以使用“权重”在匹配规则之间分配流量。

加上一点点创意(通过将相交的组拆分为唯一的子集)我们可以得到以下配置:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-route
  namespace: my-service
spec:
  hosts:
  - "service.cluster.local"
  http:
  - match:
    - headers:
        specific-id:
          regex: ^(1|3|9)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-03
      weight: 50
    - destination:
        host: "service.cluster.local"
        subset: s-05
      weight: 50
  - match:
    - headers:
        specific-id:
          regex: ^(2|10)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-03
  - match:
    - headers:
        specific-id:
          regex: ^(5|7)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-04
      weight: 50
    - destination:
        host: "service.cluster.local"
        subset: s-05
      weight: 50
  - match:
    - headers:
        specific-id:
          regex: ^(4|6|8|)$
    route:
    - destination:
        host: "service.cluster.local"
        subset: s-04

这样你可以拥有:

subset: s-03 匹配 regex: ^(1|3|9)$ OR ^(2|10)$

subset: s-04 匹配 regex: ^(5|7)$ OR ^(4|6|8|)$

subset: s-05 匹配 regex: ^(1|3|9)$ OR ^(5|7)$

正则表达式的流量:

^(1|3|9)$subset: s-03subset: s-05 之间平均分配。

^(5|7)$subset: s-04subset: s-05 之间平均分配。


使用新规则部署新模式后,istio 何时应用它? Istio 是否保证在我的所有新实例都准备好流量之前不会应用它(不删除旧规则)?

Istio 使用 envoy 进行路由,Envoy 文档有如下声明:

服务发现和动态配置: Envoy 可以选择使用一组分层的dynamic configuration APIs 进行集中管理。这些层为 Envoy 提供有关以下内容的动态更新:后端集群中的主机、后端集群本身、HTTP 路由、侦听套接字和加密材料。对于更简单的部署,后端主机发现可以是done through DNS resolution(甚至是skipped entirely),而进一步的层被静态配置文件替换。

因此,只要 istio 对象修改了 envoy 动态配置,它就会将其更改推送到 envoy 代理。是的,envoy 将确保新实例为流量做好准备,并在关闭之前优雅地耗尽旧流量。

更多信息:Runtime configurationHot restart

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-22
    • 2014-06-07
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    相关资源
    最近更新 更多