Advanced Route Rules

Before Start

You should have NO virtualservice nor destinationrule (in tutorial namespace) kubectl get virtualservice-$WORKSHOP_USER kubectl get destinationrule-$WORKSHOP_USER if so run:

./scripts/clean.sh tutorial-$WORKSHOP_USER

Smart routing based on user-agent header (Canary Deployment)

What is your user-agent?

Note: the "user-agent" header is added to OpenTracing baggage in the Customer service. From there it is automatically propagated to all downstream services. To enable automatic baggage propagation all intermediate services have to be instrumented with OpenTracing. The baggage header for user agent has following form baggage-user-agent: <value>.

Set recommendation to all v1

kubectl create -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial-$WORKSHOP_USER
kubectl create -f istiofiles/virtual-service-recommendation-v1.yml -n tutorial-$WORKSHOP_USER

Set Safari users to v2

kubectl replace -f istiofiles/virtual-service-safari-recommendation-v2.yml -n tutorial-$WORKSHOP_USER

kubectl get virtualservice -n tutorial-$WORKSHOP_USER

and test with a Safari (or even Chrome on Mac since it includes Safari in the string). Safari only sees v2 responses from recommendation

and test with a Firefox browser, it should only see v1 responses from recommendation.

There are two ways to get the URL for your browser:

You can also attempt to use the curl -A command to test with different user-agent strings.

curl -A Safari istio-ingressgateway-istio-system.apps.jconf-d4f8.openshiftworkshop.com/customer$WORKSHOP_USER
curl -A Firefox istio-ingressgateway-istio-system.apps.jconf-d4f8.openshiftworkshop.com/customer$WORKSHOP_USER

You can describe the virtualservice to see its configuration

kubectl get virtualservice -o yaml -n tutorial-$WORKSHOP_USER

Remove the Safari rule

kubectl delete -f istiofiles/virtual-service-safari-recommendation-v2.yml -n tutorial-$WORKSHOP_USER

Set mobile users to v2

kubectl create -f istiofiles/virtual-service-mobile-recommendation-v2.yml -n tutorial-$WORKSHOP_USER

curl -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4(KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" http://istio-ingressgateway-istio-system.apps.jconf-d4f8.openshiftworkshop.com/customer$WORKSHOP_USER

Clean up

kubectl delete -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial-$WORKSHOP_USER
kubectl delete -f istiofiles/virtual-service-mobile-recommendation-v2.yml -n tutorial-$WORKSHOP_USER

or you can run:

./scripts/clean.sh tutorial-$WORKSHOP_USER

Mirroring Traffic (Dark Launch)

oc get pods -l app=recommendation -n tutorial-$WORKSHOP_USER
or
kubectl get pods -l app=recommendation -n tutorial-$WORKSHOP_USER

You should have 2 pods for recommendation based on the steps above

kubectl get virtualservice -n tutorial-$WORKSHOP_USER
kubectl get destinationrule

You should have NO virtualservice nor destinationrule (in tutorial namespace) kubectl get virtualservice kubectl get destinationrule if so run:

./scripts/clean.sh tutorial-$WORKSHOP_USER

Make sure you are in the main directory of "istio-tutorial"

kubectl create -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial-$WORKSHOP_USER
kubectl create -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial-$WORKSHOP_USER

curl istio-ingressgateway-istio-system.apps.jconf-d4f8.openshiftworkshop.com/customer$WORKSHOP_USER

Check the logs of recommendation-v2

oc logs -f `oc get pods -n tutorial-$WORKSHOP_USER|grep recommendation-v2|awk '{ print $1 }'` -c recommendation -n tutorial-$WORKSHOP_USER
or
kubectl logs -f `oc get pods -n tutorial-$WORKSHOP_USER|grep recommendation-v2|awk '{ print $1 }'` -c recommendation -n tutorial-$WORKSHOP_USER

Clean up

kubectl delete -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial-$WORKSHOP_USER
kubectl delete -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial-$WORKSHOP_USER

or you can run:

./scripts/clean.sh tutorial-$WORKSHOP_USER

Load Balancer

By default, you will see "round-robin" style load-balancing, but you can change it up, with the RANDOM option being fairly visible to the naked eye.

Add another v2 pod to the mix

oc scale deployment recommendation-v2 --replicas=2 -n tutorial-$WORKSHOP_USER
or
kubectl scale deployment recommendation-v2 --replicas=2 -n tutorial-$WORKSHOP_USER

Wait a bit (oc get pods -w to watch) and curl the customer endpoint many times

curl istio-ingressgateway-istio-system.apps.jconf-d4f8.openshiftworkshop.com/customer$WORKSHOP_USER

Add a 3rd v2 pod to the mix

$ oc scale deployment recommendation-v2 --replicas=3 -n tutorial-$WORKSHOP_USER
$ oc get pods -n tutorial-$WORKSHOP_USER

or

$ kubectl scale deployment recommendation-v2 --replicas=3 -n tutorial-$WORKSHOP_USER
$ kubectl get pods -n tutorial-$WORKSHOP_USER


NAME                                  READY     STATUS    RESTARTS   AGE
customer-1755156816-cjd2z             2/2       Running   0          1h
preference-3336288630-2cc6f          2/2       Running   0          1h
recommendation-v1-3719512284-bn42p   2/2       Running   0          59m
recommendation-v2-2815683430-97nnf   2/2       Running   0          43m
recommendation-v2-2815683430-d49n6   2/2       Running   0          51m
recommendation-v2-2815683430-tptf2   2/2       Running   0          33m

Wait for those 2/2 (two containers in each pod) and then poll the customer endpoint:

The results should follow a fairly normal round-robin distribution pattern

customer => preference => recommendation v1 from '99634814-d2z2t': 1145
customer => preference => recommendation v2 from '2819441432-525lh': 1
customer => preference => recommendation v2 from '2819441432-rg45q': 2
customer => preference => recommendation v2 from '2819441432-bs5ck': 181
customer => preference => recommendation v1 from '99634814-d2z2t': 1146
customer => preference => recommendation v2 from '2819441432-rg45q': 3
customer => preference => recommendation v2 from '2819441432-rg45q': 4
customer => preference => recommendation v2 from '2819441432-bs5ck': 182

Now, add the Random LB DestinationPolicy

kubectl create -f istiofiles/destination-rule-recommendation_lb_policy_app.yml -n tutorial-$WORKSHOP_USER

And you should see a different pattern of which pod is being selected

customer => preference => recommendation v2 from '2819441432-rg45q': 10
customer => preference => recommendation v2 from '2819441432-525lh': 3
customer => preference => recommendation v2 from '2819441432-rg45q': 11
customer => preference => recommendation v1 from '99634814-d2z2t': 1153
customer => preference => recommendation v1 from '99634814-d2z2t': 1154
customer => preference => recommendation v1 from '99634814-d2z2t': 1155
customer => preference => recommendation v2 from '2819441432-rg45q': 12
customer => preference => recommendation v2 from '2819441432-525lh': 4
customer => preference => recommendation v2 from '2819441432-525lh': 5
customer => preference => recommendation v2 from '2819441432-rg45q': 13
customer => preference => recommendation v2 from '2819441432-rg45q': 14

Clean up

kubectl delete -f istiofiles/destination-rule-recommendation_lb_policy_app.yml -n tutorial-$WORKSHOP_USER

oc scale deployment recommendation-v2 --replicas=1 -n tutorial-$WORKSHOP_USER
or
kubectl scale deployment recommendation-v2 --replicas=1 -n tutorial-$WORKSHOP_USER