How to internally rewrite an URI in Istio

Viewed 122

How can I rewrite an URI in a VirtualService but just internally? In other words:

  1. A client requests api.example.com/users/get/87
  2. IngressGateway receives the request and translates it to api.example.com/get/87 to the "users" pod. The pod's web server doesn't "know" the URL "api.example.com/users/get/87" but "knows" "api.example.com/get/87"
  3. To the user's browser, it will still be appearing as "api.example.com/users/get/87" not rewrited.

I need to do it that way because there are several pod/services to respond this same domain "api.example.com"

If write it like this below, it doesn't work because it will cause conflict since I have many pod/services on the same domain:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: api
  namespace: default
spec:
  hosts:
  - "api.example.com"
  gateways:
  - istio-system/default-gateway
  http:
  - match:
    - uri:
        prefix: /users
    rewrite:  
      uri: "/"
    route:
    - destination:
        host: user
        port:
          number: 80
  - match:
    - uri:
        prefix: /cars
    rewrite:  
      uri: "/"
    route:
    - destination:
        host: user
        port:
          number: 80
1 Answers

URL rewrite - Browser URL will not be changed to redirect URL. For ex: "http://xx.xx.xx.xx:8080/api/v1/products" is the url which has been requested in browser. And in virtual service if you use rewrite: uri: /productpage. In this case the browser url will still remain "http://xx.xx.xx.xx:8080/api/v1/products" instead of "http://xx.xx.xx.xx:8080/productpage"

Related