Search code examples
envoyproxy

Multiple prefix matches for routing to same cluster in envoy


For envoy routing, I've multiple prefix matches for routing to different clusters. For routing to same cluster, I have to repeat the match section. For e.g., this is a section of routes in enovy-config.yaml

          - match:
              prefix: "/api/v1/config/"
            route:
              cluster: cluster2
          - match:
              prefix: "/api/service/risk/"
            route:
              cluster: cluster2

I cannot match on /api as most of my services start with that and I am ending up writing multiple match/prefix for routing to same cluster. Is there a way to group the prefixes that go to same cluster without having to repeat the match section? Is this even possible?


Solution

  • Essentially, no. If you want to do explicit prefix matching, then you need these repeat structures for each one.

    However, if you can instead do matching based off of a regex pattern, then you can use the safe_regex matching to route a bunch of paths to a given cluster. api docs here