Search code examples
kubernetesistioingress-controller

Istio - way to add prefix to route/destination?


Currently have Istio deployed to handle the ingress to my applications. Running into an issue where one app needs to be reachable via a certain URL such as "http://gateway/webapp1" and I need it to route internally to: server-name1:8080/some/odd/name/path

The current match statement I have is:

  - match:
    - uri:
      prefix: /webapp1
  route:
    - destination:
        host: server-name1
        port:
          number: 8080

I am unable to figure out how to expand on the destination route to tell it to hit a different endpoint that just server-name1:8080. Is there a simple way to add a prefix to the underlying route/destination? Thank you.


Solution

  • You can use the HTTP rewrite with the virtual service before sending traffic further

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: ratings-route
    spec:
      hosts:
      - ratings.prod.svc.cluster.local
      http:
      - match:
        - uri:
            prefix: /webapp1
        rewrite:
          uri: /gateway/webapp1
        route:
        - destination:
            host: server-name1
            port:
              number: 8080
    

    Read more at official document : https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRewrite