github.com/googlecloudplatform/kubernetes-workshops@v0.0.0-20180501174420-d8199445b2c3/bundles/kubernetes-101/workshop/labs/monitoring-and-health-checks.md (about) 1 # Monitoring and Health Checks 2 3 Kubernetes supports monitoring applications in the form of readiness and liveness probes. Health checks can be performed on each container in a Pod. Readiness probes indicate when a Pod is "ready" to serve traffic. Liveness probes indicate a container is "alive". If a liveness probe fails multiple times the container will be restarted. Liveness probes that continue to fail will cause a Pod to enter a crash loop. If a readiness check fails the container will be marked as not ready and will be removed from any load balancers. 4 5 In this lab you will deploy a new Pod named `healthy-monolith`, which is largely based on the `monolith` Pod with the addition of readiness and liveness probes. 6 7 In this lab you will learn how to: 8 9 * Create Pods with readiness and liveness probes 10 * Troubleshoot failing readiness and liveness probes 11 12 ## Tutorial: Creating Pods with Liveness and Readiness Probes 13 14 Explore the `healthy-monolith` pod configuration file: 15 16 ``` 17 cat pods/healthy-monolith.yaml 18 ``` 19 20 Create the `healthy-monolith` pod using kubectl: 21 22 ``` 23 kubectl create -f pods/healthy-monolith.yaml 24 ``` 25 26 ## Exercise: View Pod details 27 28 Pods will not be marked ready until the readiness probe returns an HTTP 200 response. Use the `kubectl describe` to view details for the `healthy-monolith` Pod. 29 30 ### Hints 31 32 ``` 33 kubectl describe pods <pod-name> 34 ``` 35 36 ### Quiz 37 38 * How is the readiness of the `healthy-monolith` Pod determined? 39 * How is the liveness of the `healthy-monolith` Pod determined? 40 * How often is the readiness probe checked? 41 * How often is the liveness probe checked? 42 43 > The `healthy-monolith` Pod logs each health check. Use the `kubectl logs` command to view them. 44 45 ## Tutorial: Experiment with Readiness Probes 46 47 In this tutorial you will observe how Kubernetes responds to failed readiness probes. The `monolith` container supports the ability to force failures of its readiness and liveness probes. This will enable us to simulate failures for the `healthy-monolith` Pod. 48 49 Use the `kubectl port-forward` command to forward a local port to the health port of the `healthy-monolith` Pod. 50 51 ``` 52 kubectl port-forward healthy-monolith 10081:81 53 ``` 54 55 > You now have access to the /healthz and /readiness HTTP endpoints exposed by the monolith container. 56 57 ### Experiment with Readiness Probes 58 59 Force the `monolith` container readiness probe to fail. Use the `curl` command to toggle the readiness probe status: 60 61 ``` 62 curl http://127.0.0.1:10081/readiness/status 63 ``` 64 65 Wait about 45 seconds and get the status of the `healthy-monolith` Pod using the `kubectl get pods` command: 66 67 ``` 68 kubectl get pods healthy-monolith 69 ``` 70 71 Use the `kubectl describe` command to get more details about the failing readiness probe: 72 73 ``` 74 kubectl describe pods healthy-monolith 75 ``` 76 77 > Notice the events for the `healthy-monolith` Pod report details about failing readiness probe. 78 79 Force the `monolith` container readiness probe to pass. Use the `curl` command to toggle the readiness probe status: 80 81 ``` 82 curl http://127.0.0.1:10081/readiness/status 83 ``` 84 85 Wait about 15 seconds and get the status of the `healthy-monolith` Pod using the `kubectl get pods` command: 86 87 ``` 88 kubectl get pods healthy-monolith 89 ``` 90 91 ## Exercise: Experiment with Liveness Probes 92 93 Building on what you learned in the previous tutorial use the `kubectl port-forward` and `curl` commands to force the `monolith` container liveness probe to fail. Observe how Kubernetes responds to failing liveness probes. 94 95 ### Hints 96 97 ``` 98 kubectl port-forward healthy-monolith 10081:81 99 ``` 100 101 ``` 102 curl http://127.0.0.1:10081/healthz/status 103 ``` 104 105 ### Quiz 106 107 * What happened when the liveness probe failed? 108 * What events where created when the liveness probe failed? 109 110 ## Summary 111 112 In this lab you learned that Kubernetes supports application monitoring using 113 liveness and readiness probes. You also learned how to add readiness and liveness probes to Pods and what happens when probes fail.