Run Bookinfo with Kubernetes
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
Set the
MYHOST
environment variable to hold the URL of the application:$ export MYHOST=$(kubectl config view -o jsonpath={.contexts..namespace}).bookinfo.com
Skim
bookinfo.yaml
. This is the Kubernetes deployment spec of the app. Notice the services and the deployments.Deploy the application to your Kubernetes cluster:
$ kubectl apply -l version!=v2,version!=v3 -f https://raw.githubusercontent.com/istio/istio/release-1.8/samples/bookinfo/platform/kube/bookinfo.yaml service/details created serviceaccount/bookinfo-details created deployment.apps/details-v1 created service/ratings created serviceaccount/bookinfo-ratings created deployment.apps/ratings-v1 created service/reviews created serviceaccount/bookinfo-reviews created deployment.apps/reviews-v1 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created
Check the status of the pods:
$ kubectl get pods NAME READY STATUS RESTARTS AGE details-v1-6d86fd9949-q8rrf 1/1 Running 0 10s productpage-v1-c9965499-tjdjx 1/1 Running 0 8s ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 9s reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 9s
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:$ kubectl scale deployments --all --replicas 3 deployment.apps/details-v1 scaled deployment.apps/productpage-v1 scaled deployment.apps/ratings-v1 scaled deployment.apps/reviews-v1 scaled
Check the pods status. Notice that each microservice has three pods:
$ kubectl get pods NAME READY STATUS RESTARTS AGE details-v1-6d86fd9949-fr59p 1/1 Running 0 50s details-v1-6d86fd9949-mksv7 1/1 Running 0 50s details-v1-6d86fd9949-q8rrf 1/1 Running 0 1m productpage-v1-c9965499-hwhcn 1/1 Running 0 50s productpage-v1-c9965499-nccwq 1/1 Running 0 50s productpage-v1-c9965499-tjdjx 1/1 Running 0 1m ratings-v1-7bf577cb77-cbdsg 1/1 Running 0 50s ratings-v1-7bf577cb77-cz6jm 1/1 Running 0 50s ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 1m reviews-v1-77c65dc5c6-5wt8g 1/1 Running 0 49s reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 1m reviews-v1-77c65dc5c6-r55tl 1/1 Running 0 49s
After the services achieve the
Running
status, deploy a testing pod, sleep, to use for sending requests to your microservices:$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.8/samples/sleep/sleep.yaml
To confirm that the Bookinfo application is running, send a request to it with a curl command from your testing pod:
$ kubectl exec $(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}') -c sleep -- curl productpage:9080/productpage | grep -o "<title>.*</title>" <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.
Configure the Kubernetes Ingress resource and access your application’s webpage
Create a Kubernetes Ingress resource:
$ kubectl apply -f - <<EOF apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: bookinfo annotations: kubernetes.io/ingress.class: istio spec: rules: - host: $MYHOST http: paths: - path: /productpage backend: serviceName: productpage servicePort: 9080 - path: /login backend: serviceName: productpage servicePort: 9080 - path: /logout backend: serviceName: productpage servicePort: 9080 - path: /static pathType: Prefix backend: serviceName: productpage servicePort: 9080 EOF
Update your /etc/hosts
configuration file
Get the IP address for the Kubernetes ingress named
bookinfo
:$ kubectl get ingress bookinfo
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 usesudo
to edit/etc/hosts
.$ echo $(kubectl get ingress istio-system -n istio-system -o jsonpath='{..ip} {..host}') $(kubectl get ingress bookinfo -o jsonpath='{..host}')
Access your application
Access the application’s home page from the command line:
$ curl -s $MYHOST/productpage | grep -o "<title>.*</title>" <title>Simple Bookstore App</title>
Paste the output of the following command in your browser address bar:
$ echo http://$MYHOST/productpage
You should see the following webpage:
Observe how microservices call each other. For example,
reviews
calls theratings
microservice using thehttp://ratings:9080/ratings
URL. See the code ofreviews
:private final static String ratings_service = "http://ratings:9080/ratings";
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:
$ while :; do curl -s $MYHOST/productpage | grep -o "<title>.*</title>"; sleep 1; done <title>Simple Bookstore App</title> <title>Simple Bookstore App</title> <title>Simple Bookstore App</title> <title>Simple Bookstore App</title> ...
You are ready to test the application.