用于路由到特使中的同一集群的多个前缀匹配

Multiple prefix matches for routing to same cluster in envoy

对于特使路由,我有多个前缀匹配用于路由到不同的集群。为了路由到同一个集群,我必须重复匹配部分。例如,这是 enovy-config.yaml

中的一段路线
          - match:
              prefix: "/api/v1/config/"
            route:
              cluster: cluster2
          - match:
              prefix: "/api/service/risk/"
            route:
              cluster: cluster2

我无法在 /api 上匹配,因为我的大部分服务都是从它开始的,我最终要编写多个 match/prefix 以路由到同一个集群。有没有一种方法可以将进入同一集群的前缀分组,而不必重复 match 部分?这甚至可能吗?

基本上,没有。如果要进行显式前缀匹配,则每个都需要这些重复结构。

但是,如果您可以改为基于正则表达式模式进行匹配,那么您可以使用 safe_regex 匹配将一堆路径路由到给定的集群。 api docs here