HTTP Error 503

By default, recommendation v1 and v2 are being randomly load-balanced as that is the default behavior in Kubernetes/OpenShift

If you look for all recommendations pods that contains the label app=recommendation, you will find v1 and v2.

Try: oc get pods -l app=recommendation -n tutorial

To check the random load-balance, send several requests to the microservices on Terminal 2 to see their responses
while true; do curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

Now check the files /istiofiles/destination-rule-recommendation.yml and /istiofiles/virtual-service-recommendation-503.yml.

Note that the VirtualService provides httpFault that will abort the request 50% of the time with a httpStatus=503 for the subset: app-recommendation.

To check the new behavior, make sure that the following command is running on Terminal 2:
while true; do time curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

NOTE: It might take a couple of seconds until you see the new behavior

Clean up

Don't forget to remove the virtualservice and destinationrule executing ~/projects/istio-tutorial/scripts/clean.sh

To check if you have random load-balance without 503's, try the microservice on Terminal 2: while true; do curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

Delay

The most insidious of possible distributed computing faults is not a "down" service but a service that is responding slowly, potentially causing a cascading failure in your network of services.

Check the file /istiofiles/virtual-service-recommendation-delay.yml.
and the file /istiofiles/destination-rule-recommendation.yml.

The VirtualService provides httpFault that will delay the request 50% of the time with a fixedDelay=7s.

To check the new behavior, send several requests to the microservices on Terminal 2 to see their responses
while true; do time curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

You will notice many requets to the customer endpoint now have a delay of seven seconds.

NOTE: It might take a couple of seconds until you see the new behavior

Clean up

Don't forget to remove the virtualservice and destinationrule executing ~/projects/istio-tutorial/scripts/clean.sh

To check if you have random load-balance without delays, try the microservice on Terminal 2: while true; do time curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

Retry

Instead of failing immediately, retry the Service N more times

We will make pod recommendation-v2 fail 100% of the time. Get one of the pod names from your system and replace on the following command accordingly:

The application is back to random load-balancing between v1 and v2. Check it at Terminal 2: while true; do curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

Timeout

Wait only N seconds before giving up and failing.

First, introduce some wait time in recommendations v2 by uncommenting the line 48 that call the timeout method. This method, will cause a wait time of 3 seconds. Update /recommendation-v2/src/main/java/com/redhat/developer/demos/recommendation/RecommendationVerticle.java making it a slow perfomer.

You can check the image that was create by typing docker images | grep recommendation

Now let's delete the previous v2 pod to force the creation of a new pod using the new image.

oc delete pod -l app=recommendation,version=v2 -n tutorial

To watch the creation of the pods, execute oc get pods -w

Once that the recommendation pods READY column are 2/2, you can hit CTRL+C.

Check Terminal 2 and make sure that you can see v2 responding in 3 seconds: while true; do time curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

You should see it return v1 OR 504 upstream request timeout after waiting about 1 second, although v2 takes 3 seconds to complete.

To check this behavior, send several requests to the microservices on Terminal 2 to see their responses
while true; do time curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

Clean up

To check if you have random load-balance with v2 replying in 3 seconds, try the microservice on Terminal 2: while true; do time curl http://customer-tutorial.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com; sleep .5; done

Help

Katacoda offerings an Interactive Learning Environment for Developers. This course uses a command line and a pre-configured sandboxed environment for you to use. Below are useful commands when working with the environment.

cd <directory>

Change directory

ls

List directory

echo 'contents' > <file>

Write contents to a file

cat <file>

Output contents of file

Vim

In the case of certain exercises you will be required to edit files or text. The best approach is with Vim. Vim has two different modes, one for entering commands (Command Mode) and the other for entering text (Insert Mode). You need to switch between these two modes based on what you want to do. The basic commands are: