Bookinfo Application
This example deploys a sample application composed of four separate microservices usedto demonstrate various Istio features.
The application displays information about abook, similar to a single catalog entry of an online book store. Displayedon the page is a description of the book, book details (ISBN, number ofpages, and so on), and a few book reviews.
The Bookinfo application is broken into four separate microservices:
productpage. Theproductpagemicroservice calls thedetailsandreviewsmicroservices to populate the page.details. Thedetailsmicroservice contains book information.reviews. Thereviewsmicroservice contains book reviews. It also calls theratingsmicroservice.ratings. Theratingsmicroservice contains book ranking information that accompanies a book review.
There are 3 versions of thereviews microservice:
- Version v1 doesn’t call the
ratingsservice. - Version v2 calls the
ratingsservice, and displays each rating as 1 to 5 black stars. - Version v3 calls the
ratingsservice, and displays each rating as 1 to 5 red stars.
The end-to-end architecture of the application is shown below.
This application is polyglot, i.e., the microservices are written in different languages.It’s worth noting that these services have no dependencies on Istio, but make an interestingservice mesh example, particularly because of the multitude of services, languages and versionsfor thereviews service.
Before you begin
If you haven’t already done so, setup Istio by following the instructionsin theinstallation guide.
Istio supports the KubernetesGateway API and intends to make it the default API for traffic management in the future.The following instructions allow you to choose to use either the Gateway API or the Istio configuration API when configuringtraffic management in the mesh. Follow instructions under either theGateway API orIstio APIs tab,according to your preference.
Note that the Kubernetes Gateway API CRDs do not come installed by default on most Kubernetes clusters, so make sure they areinstalled before using the Gateway API:
$ kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \ kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.4.0/experimental-install.yamlDeploying the application
To run the sample with Istio requires no changes to theapplication itself. Instead, you simply need to configure and run the services in anIstio-enabled environment, with Envoy sidecars injected along side each service.The resulting deployment will look like this:
All of the microservices will be packaged with an Envoy sidecar that intercepts incomingand outgoing calls for the services, providing the hooks needed to externally control,via the Istio control plane, routing, telemetry collection, and policy enforcementfor the application as a whole.
Start the application services
Change directory to the root of the Istio installation.
The default Istio installation usesautomatic sidecar injection.Label the namespace that will host the application with
istio-injection=enabled:$ kubectl label namespace default istio-injection=enabledDeploy your application using the
kubectlcommand:$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo.yaml@The command launches all four services shown in the
bookinfoapplication architecture diagram.All 3 versions of the reviews service, v1, v2, and v3, are started.Confirm all services and pods are correctly defined and running:
$ kubectl get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdetails ClusterIP 10.0.0.31 <none> 9080/TCP 6mkubernetes ClusterIP 10.0.0.1 <none> 443/TCP 7dproductpage ClusterIP 10.0.0.120 <none> 9080/TCP 6mratings ClusterIP 10.0.0.15 <none> 9080/TCP 6mreviews ClusterIP 10.0.0.170 <none> 9080/TCP 6mand
$ kubectl get podsNAME READY STATUS RESTARTS AGEdetails-v1-1520924117-48z17 2/2 Running 0 6mproductpage-v1-560495357-jk1lz 2/2 Running 0 6mratings-v1-734492171-rnr5l 2/2 Running 0 6mreviews-v1-874083890-f0qf0 2/2 Running 0 6mreviews-v2-1343845940-b34q5 2/2 Running 0 6mreviews-v3-1813607990-8ch52 2/2 Running 0 6mTo confirm that the Bookinfo application is running, send a request to it by a
curlcommand from some pod, forexample fromratings:$ kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"<title>Simple Bookstore App</title>
Determine the ingress IP and port
Now that the Bookinfo services are up and running, you need to make the application accessible from outside of yourKubernetes cluster, e.g., from a browser. A gateway is used for this purpose.
Create a gateway for the Bookinfo application:
Create anIstio Gateway using the following command:
$ kubectl apply -f @samples/bookinfo/networking/bookinfo-gateway.yaml@gateway.networking.istio.io/bookinfo-gateway createdvirtualservice.networking.istio.io/bookinfo createdConfirm the gateway has been created:
$ kubectl get gatewayNAME AGEbookinfo-gateway 32sFollowthese instructions to set the
INGRESS_HOSTandINGRESS_PORTvariables for accessing the gateway. Return here, when they are set.These instructions assume that your Kubernetes cluster supports external load balancers (i.e., Services of typeLoadBalancer).Refer toingress control for details.Create aKubernetes Gateway using the following command:
$ kubectl apply -f @samples/bookinfo/gateway-api/bookinfo-gateway.yaml@gateway.gateway.networking.k8s.io/bookinfo-gateway createdhttproute.gateway.networking.k8s.io/bookinfo createdBecause creating a Kubernetes
Gatewayresource will alsodeploy an associated proxy service,run the following command to wait for the gateway to be ready:$ kubectl wait --for=condition=programmed gtw bookinfo-gatewayGet the gateway address and port from the bookinfo gateway resource:
$ export INGRESS_HOST=$(kubectl get gtw bookinfo-gateway -o jsonpath='{.status.addresses[0].value}')$ export INGRESS_PORT=$(kubectl get gtw bookinfo-gateway -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')Set
GATEWAY_URL:$ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
Confirm the app is accessible from outside the cluster
To confirm that the Bookinfo application is accessible from outside the cluster, run the followingcurl command:
$ curl -s "http://${GATEWAY_URL}/productpage" | grep -o "<title>.*</title>"<title>Simple Bookstore App</title>You can also point your browser tohttp://$GATEWAY_URL/productpageto view the Bookinfo web page. If you refresh the page several times, you shouldsee different versions of reviews shown inproductpage, presented in a round robin style (redstars, black stars, no stars), since we haven’t yet used Istio to control theversion routing.
Define the service versions
Before you can use Istio to control the Bookinfo version routing, you need to define the availableversions.
Istio usessubsets, indestination rules,to define versions of a service.Run the following command to create default destination rules for the Bookinfo services:
$ kubectl apply -f @samples/bookinfo/networking/destination-rule-all.yaml@default anddemoconfiguration profiles haveauto mutual TLS enabled by default.To enforce mutual TLS, use the destination rules insamples/bookinfo/networking/destination-rule-all-mtls.yaml.Wait a few seconds for the destination rules to propagate.
You can display the destination rules with the following command:
$ kubectl get destinationrules -o yamlUnlike the Istio API, which usesDestinationRule subsets to define the versions of a service,the Kubernetes Gateway API uses backend service definitions for this purpose.
Run the following command to create backend service definitions for the three versions of thereviews service:
$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo-versions.yaml@What’s next
You can now use this sample to experiment with Istio’s features fortraffic routing, fault injection, rate limiting, etc.To proceed, refer to one or more of theIstio Tasks,depending on your interest.Configuring Request Routingis a good place to start for beginners.
Cleanup
When you’re finished experimenting with the Bookinfo sample, uninstall and cleanit up using the following command:
$ @samples/bookinfo/platform/kube/cleanup.sh@