Run Bookinfo with Kubernetes

This is work in progress. We will add its sections in pieces. Your feedback is welcome at discuss.istio.io.

This module shows you an application composed of four microservices written in different programming languages: productpage, details, ratings and reviews. We call the composed application Bookinfo, and you can learn more about it on the Bookinfo example page.

The Bookinfo example shows the final state of the application, in which the reviews microservice has three versions: v1, v2, v3. In this module, the application only uses the v1 version of the reviews microservice. The next modules enhance the application by deploying newer versions of the reviews microservice.

Deploy the application and a testing pod

  1. Set the MYHOST environment variable to hold the URL of the application:

    1. $ export MYHOST=$(kubectl config view -o jsonpath={.contexts..namespace}).bookinfo.com
  2. Skim bookinfo.yaml. This is the Kubernetes deployment spec of the app. Notice the services and the deployments.

  3. Deploy the application to your Kubernetes cluster:

    1. $ kubectl apply -l version!=v2,version!=v3 -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/platform/kube/bookinfo.yaml
    2. service/details created
    3. serviceaccount/bookinfo-details created
    4. deployment.apps/details-v1 created
    5. service/ratings created
    6. serviceaccount/bookinfo-ratings created
    7. deployment.apps/ratings-v1 created
    8. service/reviews created
    9. serviceaccount/bookinfo-reviews created
    10. deployment.apps/reviews-v1 created
    11. service/productpage created
    12. serviceaccount/bookinfo-productpage created
    13. deployment.apps/productpage-v1 created
  4. Check the status of the pods:

    1. $ kubectl get pods
    2. NAME READY STATUS RESTARTS AGE
    3. details-v1-6d86fd9949-q8rrf 1/1 Running 0 10s
    4. productpage-v1-c9965499-tjdjx 1/1 Running 0 8s
    5. ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 9s
    6. reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 9s
  5. After the four pods achieve the Running status, you can scale the deployment. To let each version of each microservice run in three pods, execute the following command:

    1. $ kubectl scale deployments --all --replicas 3
    2. deployment.apps/details-v1 scaled
    3. deployment.apps/productpage-v1 scaled
    4. deployment.apps/ratings-v1 scaled
    5. deployment.apps/reviews-v1 scaled
  6. Check the pods status. Notice that each microservice has three pods:

    1. $ kubectl get pods
    2. NAME READY STATUS RESTARTS AGE
    3. details-v1-6d86fd9949-fr59p 1/1 Running 0 50s
    4. details-v1-6d86fd9949-mksv7 1/1 Running 0 50s
    5. details-v1-6d86fd9949-q8rrf 1/1 Running 0 1m
    6. productpage-v1-c9965499-hwhcn 1/1 Running 0 50s
    7. productpage-v1-c9965499-nccwq 1/1 Running 0 50s
    8. productpage-v1-c9965499-tjdjx 1/1 Running 0 1m
    9. ratings-v1-7bf577cb77-cbdsg 1/1 Running 0 50s
    10. ratings-v1-7bf577cb77-cz6jm 1/1 Running 0 50s
    11. ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 1m
    12. reviews-v1-77c65dc5c6-5wt8g 1/1 Running 0 49s
    13. reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 1m
    14. reviews-v1-77c65dc5c6-r55tl 1/1 Running 0 49s
  7. After the services achieve the Running status, deploy a testing pod, curl, to use for sending requests to your microservices:

    1. $ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/curl/curl.yaml
  8. To confirm that the Bookinfo application is running, send a request to it with a curl command from your testing pod:

    1. $ kubectl exec $(kubectl get pod -l app=curl -o jsonpath='{.items[0].metadata.name}') -c curl -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
    2. <title>Simple Bookstore App</title>

Enable external access to the application

Once your application is running, enable clients from outside the cluster to access it. Once you configure the steps below successfully, you can access the application from your laptop’s browser.

If your cluster runs on GKE, change the productpage service type to LoadBalancer:

  1. $ kubectl patch svc productpage -p '{"spec": {"type": "LoadBalancer"}}'
  2. service/productpage patched

Configure the Kubernetes Ingress resource and access your application’s webpage

  1. Create a Kubernetes Ingress resource:

    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.k8s.io/v1
    3. kind: Ingress
    4. metadata:
    5. name: bookinfo
    6. annotations:
    7. kubernetes.io/ingress.class: istio
    8. spec:
    9. rules:
    10. - host: $MYHOST
    11. http:
    12. paths:
    13. - path: /productpage
    14. pathType: Prefix
    15. backend:
    16. service:
    17. name: productpage
    18. port:
    19. number: 9080
    20. - path: /login
    21. pathType: Prefix
    22. backend:
    23. service:
    24. name: productpage
    25. port:
    26. number: 9080
    27. - path: /logout
    28. pathType: Prefix
    29. backend:
    30. service:
    31. name: productpage
    32. port:
    33. number: 9080
    34. - path: /static
    35. pathType: Prefix
    36. backend:
    37. service:
    38. name: productpage
    39. port:
    40. number: 9080
    41. EOF

Update your /etc/hosts configuration file

  1. Get the IP address for the Kubernetes ingress named bookinfo:

    1. $ kubectl get ingress bookinfo
  2. In your /etc/hosts file, add the previous IP address to the host entries provided by the following command. You should have a Superuser privilege and probably use sudo to edit /etc/hosts.

    1. $ echo $(kubectl get ingress istio-system -n istio-system -o jsonpath='{..ip} {..host}') $(kubectl get ingress bookinfo -o jsonpath='{..host}')

Access your application

  1. Access the application’s home page from the command line:

    1. $ curl -s $MYHOST/productpage | grep -o "<title>.*</title>"
    2. <title>Simple Bookstore App</title>
  2. Paste the output of the following command in your browser address bar:

    1. $ echo http://$MYHOST/productpage

    You should see the following webpage:

    Bookinfo Web Application
    Bookinfo Web Application
  3. Observe how microservices call each other. For example, reviews calls the ratings microservice using the http://ratings:9080/ratings URL. See the code of reviews:

    1. private final static String ratings_service = "http://ratings:9080/ratings";
  4. Set an infinite loop in a separate terminal window to send traffic to your application to simulate the constant user traffic in the real world:

    1. $ while :; do curl -s $MYHOST/productpage | grep -o "<title>.*</title>"; sleep 1; done
    2. <title>Simple Bookstore App</title>
    3. <title>Simple Bookstore App</title>
    4. <title>Simple Bookstore App</title>
    5. <title>Simple Bookstore App</title>
    6. ...

You are ready to test the application.