Search code examples
kuberneteskubernetes-ingressistioenvoyproxyistio-gateway

How to create prefix matches in Istio VirtualService for substring paths


I'm encountering a warning message about duplicate/overlapping matches in my Istio VirtualService configuration, and I'm seeking assistance in resolving it. Here's the warning message:

Warning: virtualService rule #1 match #0 of prefix /apparchived/ is not used (duplicate/overlapping match in rule #1 of prefix /app on #0)

I have a VirtualService configuration where I need to route requests for paths /app and /apparchived to different services while preserving the URI paths. However, I'm facing issues with overlapping matches in my configuration.

Here's my current VirtualService configuration:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: app
  namespace: ingress-routes
spec:
  hosts:
  - "*"
  gateways:
  - dev-app-gateway
  http:
  - match:
    - uri:
        prefix: "/app/"
    - uri:
        prefix: "/app"
    rewrite:
      uri: "/"        
    route:
    - destination:
        host: app.app.svc.cluster.local
        port:
          number: 80
  - match:
    - uri:
        prefix: "/apparchived/"
    - uri:
        prefix: "/apparchived"        
    rewrite:
      uri: "/"        
    route:
    - destination:
        host: apparchived.app.svc.cluster.locala
          number: 80

I'd like to achieve the following routing behavior:

  • Requests to /app should be routed to service app.app.svc.cluster.local.
  • Requests to /apparchived should be routed to service apparchived.app.svc.cluster.local.
  • At the same time /app/ & /apparchived/ also should route to respective services. Any insights on how to resolve the warning and achieve the desired routing behavior would be greatly appreciated.

Thank you!


Solution

  • Please use "exact" and "prefix" attributes combination to achieve desired routing you are looking for. Please use below virtual service definition to avoid "duplicate/overlapping match in rule warning"

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: app
      namespace: ingress-routes
    spec:
      hosts:
      - "*"
      gateways:
      - dev-app-gateway
      http:
      - match:
        - uri:
            prefix: "/app/"
        - uri:
            exact: "/app"
        rewrite:
          uri: "/"        
        route:
        - destination:
            host: app.app.svc.cluster.local
            port:
              number: 80
      - match:
        - uri:
            prefix: "/apparchived/"
        - uri:
            exact: "/apparchived"        
        rewrite:
          uri: "/"        
        route:
        - destination:
            host: apparchived.app.svc.cluster.local
              number: 80