how can I add a rewrite uri in the destination of virtual service how can I add a rewrite uri in the destination of virtual service kubernetes kubernetes

how can I add a rewrite uri in the destination of virtual service


There are couple of things you are not doing, I would say. First of all to do canary, you don't do it for two different services, but your do for two subsets of the same service. In the end, there are two different deployments, but you need to define just one service, then through a DestinationRule you define the subsets.

In other words, you have two deployments right? These two deployments will have one common label, and one label that differs. Through the common labels you will define DESTINATION_HOST_THAT_HAS_SUBSETS, and through the labels that differs you would define the subsets service1host and service2host.

Then, your VirtualService will look like this:

apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: server-vsspec:  hosts:  - DESTINATION_HOST_THAT_HAS_SUBSETS  http:  - match:    - uri:        prefix: /path1    rewrite:      uri: /path1modified    route:    - destination:        host: DESTINATION_HOST_THAT_HAS_SUBSETS        subset: service1host      weight: 50    route:    - destination:        host: DESTINATION_HOST_THAT_HAS_SUBSETS        subset: service2host      weight: 50

UPDATE

After jt97's comment, which is correct about being possible to have two separate services, this VirtualService should work as well.

apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:  name: server-vsspec:  hosts:  - DESTANTION_HOST  http:  - match:    - uri:        prefix: /path1    rewrite:      uri: /path1modified    route:    - destination:        host: service1host      weight: 50    route:    - destination:        host: service2host      weight: 50


As far as I know that's not possible to do.

If you take a look at istio documentation about rewrite in virtual service, rewrite is part of http, so it cannot be used in destination.

Link which might be helpful with weight-based routing: