kuberneteskubernetes-ingressistiocontextpath

Routing requests to services based on URI prefix in Istio VS


This is what I want to achieve: Route traffic to a service based on the URI prefix

Problem I'm facing: Unable to segregate the prefix from the context path

Explanation:

I want to route traffic to a services based on the prefix. Say, /dev/service/context/path/ and /test/service/context/path/ . But I'm not able to do so without changing the context path of the application itself.

Is there a way I can segregate the prefix part of URI from the context path of application?

This is what my VS looks like:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: servicea
  namespace: dev
spec:
  hosts:
  - "*"
  gateways:
  - dev-gateway
  http:
  - match:
    - uri:
        prefix: /dev
    route:
    - destination:
        port:
          number: 8080
        host: servicea

Thanks


Solution

  • Not sure if I understand your question correctly. I guess you can just add a rewrite rule like this:

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: servicea
      namespace: dev
    spec:
      hosts:
      - "*"
      gateways:
      - dev-gateway
      http:
      - match:
        - uri:
            prefix: /dev
        rewrite:
           uri: /
        route:
        - destination:
            port:
              number: 8080
            host: servicea
    

    By this your traffic for /dev/service/context/path/ becomes /service/context/path/.