Adding tutorial modules: containerize, deploy, and test (#5485)

* Added first draft of three modules

* New links, linter fixes, grammar

* Fixed variable steps, sequencing, removed TODO

* Fixed linter error

* GKE note and config verification steps

* Fixed typo

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-ratings-in-docker/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-ratings-in-docker/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-bookinfo-with-kubernetes/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-ratings-in-docker/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/setup-local-computer/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/testing-in-production/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Update content/en/docs/examples/microservices-istio/run-ratings-in-docker/index.md

Co-Authored-By: Rigs Caballero <grca@google.com>

* Implemented review comments

* Fixed bad link

* Fixed linter failure

* Fixed link and warning indent
This commit is contained in:
Adam Miller 2019-12-17 17:26:24 -08:00 committed by Istio Automation
parent 38a997a026
commit cfacac51b7
8 changed files with 409 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

View File

@ -0,0 +1,210 @@
---
title: Run Bookinfo with Kubernetes
overview: Deploy the Bookinfo application that uses the ratings microservice in Kubernetes.
weight: 30
---
{{< boilerplate work-in-progress >}}
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 in the [Bookinfo example](/docs/examples/bookinfo) page.
The version of the application used in the example can be viewed as the final version since 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 with multiple versions of the `reviews` microservice.
## Deploy the application and a testing pod
1. Set the value of the `NAMESPACE` environmental variable to `tutorial`:
{{< text bash >}}
$ export NAMESPACE=tutorial
{{< /text >}}
1. Set the value of the `KUBECONFIG` environmental variable to the path of file you created in the previous module:
{{< text bash >}}
$ export KUBECONFIG=./${NAMESPACE}-user-config.yaml
{{< /text >}}
1. Set the `MYHOST` environmental variable to hold the URL of the application:
{{< text bash >}}
$ export MYHOST=$(kubectl config view -o jsonpath={.contexts..namespace}).bookinfo.com
{{< /text >}}
1. Skim [`bookinfo.yaml`]({{< github_blob >}}/samples/bookinfo/platform/kube/bookinfo.yaml).
This is the Kubernetes deployment spec of the app. Notice the services and the deployments.
1. Deploy the application to your Kubernetes cluster on the `tutorial` namespace:
{{< text bash >}}
$ kubectl apply -l version!=v2,version!=v3 -f {{< github_file >}}/samples/bookinfo/platform/kube/bookinfo.yaml
service "details" created
deployment "details-v1" created
service "ratings" created
deployment "ratings-v1" created
service "reviews" created
deployment "reviews-v1" created
service "productpage" created
deployment "productpage-v1" created
{{< /text >}}
1. Check the status of the pods:
{{< text bash >}}
$ 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
{{< /text >}}
1. After the four services achieve the `Running` status, you can scale the deployment. To let each version of each microservice run in three pods, execute the following command:
{{< text bash >}}
$ kubectl scale deployments --all --replicas 3
deployment "details-v1" scaled
deployment "productpage-v1" scaled
deployment "ratings-v1" scaled
deployment "reviews-v1" scaled
deployment "reviews-v2" scaled
deployment "reviews-v3" scaled
{{< /text >}}
1. Check the pods status. Notice that each microservice has three pods:
{{< text bash >}}
$ 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
{{< /text >}}
1. Deploy a testing pod, [sleep]({{< github_tree >}}/samples/sleep), to use it for sending
requests to your microservices:
{{< text bash >}}
$ kubectl apply -f {{< github_file >}}/samples/sleep/sleep.yaml
{{< /text >}}
1. To confirm that the Bookinfo application is running, send a request to it with a curl command from your testing pod:
{{< text bash >}}
$ kubectl exec -it $(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>
{{< /text >}}
## Enable external access to the application
Once your application is running, enable clients from outside the cluster to access it. Such clients are known as mesh-external clients. Once you
configure the steps below successfully, you can access the application from your laptop's browser.
{{< warning >}}
If your cluster runs on GKE, change the `productpage` service type to `LoadBalancer` before you create your Kubernetes ingress, as shown in this example:
{{< text yaml >}}
selector:
app: productpage
sessionAffinity: None
type: LoadBalancer
{{< /text >}}
{{< /warning >}}
### Configure the Kubernetes Ingress resource and access your application's webpage
1. Create a Kubernetes Ingress resource:
{{< text bash >}}
$ kubectl apply -f - <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: bookinfo
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
EOF
{{< /text >}}
### Update your `/etc/hosts` configuration file
1. Append the output of the following command to `/etc/hosts`. You should have a
[Superuser](https://en.wikipedia.org/wiki/Superuser) privilege and probably use
[`sudo`](https://en.wikipedia.org/wiki/Sudo) to run the command.
{{< text bash >}}
$ echo $(kubectl get ingress istio-system -n istio-system -o jsonpath='{..ip} {..host}') $(kubectl get ingress bookinfo -o jsonpath='{..host}')
{{< /text >}}
### Access your application
1. Access the application's home page from the command line:
{{< text bash >}}
$ curl -s $MYHOST/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
{{< /text >}}
1. Paste the output of the following command in your browser address bar:
{{< text bash >}}
$ echo http://$MYHOST/productpage
{{< /text >}}
You should see the following webpage:
{{< image width="80%"
link="bookinfo.png"
caption="Bookinfo Web Application"
>}}
1. 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`]({{< github_blob >}}/samples/bookinfo/src/reviews/reviews-application/src/main/java/application/rest/LibertyRestEndpoint.java):
{{< text java >}}
private final static String ratings_service = "http://ratings:9080/ratings";
{{< /text >}}
1. 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:
{{< text bash >}}
$ 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>
...
{{< /text >}}
You are ready to [test the application](/docs/examples/microservices-istio/production-testing).

View File

@ -0,0 +1,72 @@
---
title: Run ratings in Docker
overview: Run a single microservice in a Docker container.
weight: 20
---
{{< boilerplate work-in-progress >}}
This module shows how you create a [Docker](https://www.docker.com) image and run it locally.
1. Download the [`Dockerfile`](https://docs.docker.com/engine/reference/builder/) for the `ratings` microservice.
{{< text bash >}}
$ curl -s {{< github_file >}}/samples/bookinfo/src/ratings/Dockerfile -o Dockerfile
{{< /text >}}
1. Observe the `Dockerfile`.
{{< text bash >}}
$ cat Dockerfile
{{< /text >}}
Note that it copies the files
into the container's filesystem and then runs the `npm install` command you ran in the previous module.
The `CMD` command instructs Docker to run the `ratings` service on port `9080`.
1. Build a Docker image from the `Dockerfile`:
{{< text bash >}}
$ docker build -t $USER/ratings .
...
Step 9/9 : CMD node /opt/microservices/ratings.js 9080
---> Using cache
---> 77c6a304476c
Successfully built 77c6a304476c
Successfully tagged user/ratings:latest
{{< /text >}}
1. Run ratings in Docker. The following [docker run](https://docs.docker.com/engine/reference/commandline/run/) command
instructs Docker to expose port `9080` of the container to port `9081` of your computer, allowing you to access the
`ratings` microservice on port `9081`.
{{< text bash >}}
$ docker run -d -p 9081:9080 $USER/ratings
{{< /text >}}
1. Access [http://localhost:9081/ratings/7](http://localhost:9081/ratings/7) in your browser or use the following `curl` command:
{{< text bash >}}
$ curl localhost:9081/ratings/7
{"id":7,"ratings":{"Reviewer1":5,"Reviewer2":4}}
{{< /text >}}
1. Observe the running container. Run the [docker ps](https://docs.docker.com/engine/reference/commandline/ps/) command
to list all the running containers and notice the container with the image `<your user name>/ratings`.
{{< text bash >}}
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47e8c1fe6eca user/ratings "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:9081->9080/tcp elated_stonebraker
...
{{< /text >}}
1. Stop the running container:
{{< text bash >}}
$ docker stop <the container ID from the output of docker ps>
{{< /text >}}
You are ready to [deploy the application](/docs/examples/microservices-istio/bookinfo-kubernetes).

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -0,0 +1,100 @@
---
title: Testing in production
overview: Testing a new version of a microservice in production.
weight: 40
---
{{< boilerplate work-in-progress >}}
Test your microservice, in production!
## Testing individual microservices
1. Issue an HTTP request from the testing pod to one of your services:
{{< text bash >}}
$ kubectl exec -it $(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}') -- curl http://ratings:9080/ratings/7
{{< /text >}}
## Chaos testing
Perform some [chaos testing](http://www.boyter.org/2016/07/chaos-testing-engineering/)
in production and see how your application reacts. After each chaos operation,
access the application's webpage and see if anything changed. Check
the pods' status with `kubectl get pods`.
1. Terminate the `details` service in one pod.
{{< text bash >}}
$ kubectl exec -it $(kubectl get pods -l app=details -o jsonpath='{.items[0].metadata.name}') -- pkill ruby
{{< /text >}}
1. Check the pods status:
{{< text bash >}}
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-6d86fd9949-fr59p 1/1 Running 1 47m
details-v1-6d86fd9949-mksv7 1/1 Running 0 47m
details-v1-6d86fd9949-q8rrf 1/1 Running 0 48m
productpage-v1-c9965499-hwhcn 1/1 Running 0 47m
productpage-v1-c9965499-nccwq 1/1 Running 0 47m
productpage-v1-c9965499-tjdjx 1/1 Running 0 48m
ratings-v1-7bf577cb77-cbdsg 1/1 Running 0 47m
ratings-v1-7bf577cb77-cz6jm 1/1 Running 0 47m
ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 48m
reviews-v1-77c65dc5c6-5wt8g 1/1 Running 0 47m
reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 48m
reviews-v1-77c65dc5c6-r55tl 1/1 Running 0 47m
sleep-88ddbcfdd-l9zq4 1/1 Running 0 47m
{{< /text >}}
Note that the first pod was restarted once.
1. Terminate the `details` service in all its pods:
{{< text bash >}}
$ for pod in $(kubectl get pods -l app=details -o jsonpath='{.items[*].metadata.name}'); do echo terminating $pod; kubectl exec -it $pod -- pkill ruby; done
{{< /text >}}
1. Check the webpage of the application:
{{< image width="80%"
link="bookinfo-details-unavailable.png"
caption="Bookinfo Web Application, details unavailable"
>}}
Note that the details section contains error messages instead of book details.
1. Check the pods status:
{{< text bash >}}
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-6d86fd9949-fr59p 1/1 Running 2 48m
details-v1-6d86fd9949-mksv7 1/1 Running 1 48m
details-v1-6d86fd9949-q8rrf 1/1 Running 1 49m
productpage-v1-c9965499-hwhcn 1/1 Running 0 48m
productpage-v1-c9965499-nccwq 1/1 Running 0 48m
productpage-v1-c9965499-tjdjx 1/1 Running 0 48m
ratings-v1-7bf577cb77-cbdsg 1/1 Running 0 48m
ratings-v1-7bf577cb77-cz6jm 1/1 Running 0 48m
ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 49m
reviews-v1-77c65dc5c6-5wt8g 1/1 Running 0 48m
reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 49m
reviews-v1-77c65dc5c6-r55tl 1/1 Running 0 48m
sleep-88ddbcfdd-l9zq4 1/1 Running 0 48m
{{< /text >}}
The first pod restarted twice and two other `details` pods
restarted once. You may experience the `Error` and the
`CrashLoopBackOff` statuses until the pods reach `Running` status.
In both cases, the application did not crash. The crash in the
`details` microservice did not cause other microservices to fail. This behavior means you
did not have a **cascading failure** in this situation. Instead, you had
**gradual service degradation**: despite one microservice crashing, the
application could still provide useful functionality. It displayed the reviews and the
basic information about the book.

View File

@ -38,7 +38,7 @@ proceed to [setting up your local computer](/docs/examples/microservices-istio/s
simultaneously by multiple participants.
{{< /tip >}}
1. Install Istio with strict mutual TLS enabled. TODO: add command or point to instructions.
1. [Install Istio](/docs/setup/) with strict mutual TLS enabled.
1. [Enable Envoy's access logging](/docs/tasks/observability/logs/access-log/#enable-envoy-s-access-logging).
@ -213,6 +213,22 @@ proceed to [setting up your local computer](/docs/examples/microservices-istio/s
EOF
{{< /text >}}
1. Set the `KUBECONFIG` environment variable for the `${NAMESPACE}-user-config.yaml`
configuration file:
{{< text bash >}}
$ export KUBECONFIG=./${NAMESPACE}-user-config.yaml
{{< /text >}}
1. Verify that the configuration took effect by printing the current namespace:
{{< text bash >}}
$ kubectl config view -o jsonpath="{.contexts[?(@.name==\"$(kubectl config current-context)\")].context.namespace}"
tutorial
{{< /text >}}
You should see the name of your namespace in the output.
1. If you are setting up the cluster for yourself, copy the
`${NAMESPACE}-user-config.yaml` file mentioned in the previous steps to your
local computer, where `${NAMESPACE}` is the name of the namespace you

View File

@ -8,6 +8,14 @@ weight: 3
In this module you prepare your local computer for the tutorial.
1. On your local computer, create an environment variable to store the name
of the namespace used when you run the tutorial commands.
You can use any name, for example `tutorial`.
{{< text bash >}}
$ export NAMESPACE=tutorial
{{< /text >}}
1. On your local computer, locate the `${NAMESPACE}-user-config.yaml` file you
created earlier in the tutorial, where `${NAMESPACE}` is the name of your
namespace. For example `tutorial-user-config.yaml`.

View File

@ -107,7 +107,7 @@ Since you run the `ratings` service locally, you can also access it via the
{"id":7,"ratings":{"Reviewer1":5,"Reviewer2":4}}
{{< /text >}}
1. Use the `POST` method of the `curl` command to set the ratings for the
1. Open a different terminal session and use the `POST` method of the `curl` command to set the ratings for the
product to `1`:
{{< text bash >}}
@ -126,4 +126,4 @@ Since you run the `ratings` service locally, you can also access it via the
Congratulations, you can now build, test, and run a service on your local computer!
You are ready to learn how to package the service into a container.
You are ready to [package the service](/docs/examples/microservices-istio/package-service) into a container.