Set weight for the destination based on attribute value in http request payload


#1

Hi

I am new to Istio/Envoy.

I am trying to configure weight for the destination at runtime because the weight will be decided based on the value set in one of attribute in request payload. can it solved with istio/envoy. Could you please provide any samples!

Thanks
Asis


#2

Hi Asis,
If I understand well your use case, you would like to redirect the request to a specific version depending on an attribute set in the request. You shouldn’t (and you couldn’t) configure dynamically the destination weight at runtime. Instead, Istio support traffic routing depending on http headers:

Let’s assume that you have a service with two versions: v1 and v2 and you have a HTTP header called ‘user-type’ that can have ‘internal’ or ‘external’ value.
You would like to redirect internal users to new version v2. Here is how you should process:

First, you need to define the destination rule:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: destination-rule-myservice
spec:
  host: myservice-host
  subsets:
    - name: v1
      labels:
        version: '1.0'
    - name: v2
      labels:
        version: '2.0'

And then apply the VirtualService telling to Istio that each HTTP request with a header ‘user-type’ equal to ‘internal’ should be redirected to v2 :

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtual-service-myservice
spec:
  hosts:
    - '*'
  gateways:
    - myservice-gateway
  http:
    - match:
        - headers:
            user-type:
              excat: 'internal'
      route:
        - destination:
            host: myservice-host
            subset: v2
    - route:
        - destination:
            host: myservice-host
            subset: v1

More documentation can be find at: