
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Configure Liveness Probes
/ 50
Configure Readiness Probes
/ 50
In this lab, you will configure and test Kubernetes liveness and readiness probes for containers.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
After you complete the initial sign-in steps, the project dashboard appears.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
In this task, you connect to the lab GKE Cluster and clone the lab repository to the lab cloud shell.
In this task, you will deploy a liveness probe to detect applications that have transitioned from a running state to a broken state. Sometimes, applications are temporarily unable to serve traffic. For example, an application might need to load large data or configuration files during startup.
In such cases, you don't want to kill the application, but you don't want to send it requests either. Kubernetes provides readiness probes to detect and mitigate these situations. A Pod with containers reporting that they are not ready does not receive traffic through Kubernetes Services.
Readiness probes are configured similarly to liveness probes. The only difference is that you use the readinessProbe field instead of the livenessProbe field.
A Pod definition file called exec-liveness.yaml
has been provided for you that defines a simple container called liveness
running Busybox and a liveness probe that uses the cat
command against the file /tmp/healthy
within the container to test for liveness every 5 seconds.
The startup script for the liveness
container creates the /tmp/healthy
on startup and then deletes it 30 seconds later to simulate an outage that the Liveness probe can detect.
The output indicates that no liveness probes have failed yet.
Condensed sample output:
The sample output shown here has been condensed for readability, you will see a lot more detail on screen.
At the bottom of the output, there are messages indicating that the liveness probes have failed, and the containers have been killed and recreated.
Condensed sample output:
The output shows that RESTARTS has been incremented in response to the failure detected by the liveness probe:
Sample output:
Click Check my progress to verify the objective.
Although a pod could successfully start and be considered healthy by a liveness probe, it's likely that it may not be ready to receive traffic right away. This is common for deployments that serve as a backend to a service such as a load balancer. A readiness probe is used to determine when a pod and its containers are ready to begin receiving traffic.
Readiness probes are configured similarly to liveness probes. The only difference in configuration is that you use the readinessProbe field instead of the livenessProbe field. Readiness probes control whether a specific container is considered ready, and this is used by services to decide when a container can have traffic sent to it.
In this task a Pod definition file called readiness-deployment.yaml
has been provided for you that create a single pods that will serve as a test web server along with a load balancer
The container has a readiness probe defined that uses the cat
command against the file /tmp/healthz
within the container to test for readiness every 5 seconds.
Each container also has a liveness probe defined that uses the cat
command against the same file within the container to test for readiness every 5 seconds but it also has a startup delay of 45 seconds to simulate an application that might have a complex startup process that takes time to stabilize after a container has started.
Once the service has started handling traffic this pattern ensures that the service will forward traffic only to containers that are ready to handle traffic.
readiness-demo-svc
load balancer service:Enter the IP address in a browser window and you'll notice that you'll get an error message signifying that the site cannot be reached.
Check the pod's events:
The output will reveal that the readiness probe has failed:
Unlike the liveness probe, an unhealthy readiness probe does not trigger the pod to restart.
The Conditions
section of the pod description should now show True
as the value for Ready
.
Output:
Setting meaningful readiness probes for your application containers ensures that pods are only receiving traffic when they are ready to do so. An example of a meaningful readiness probe is checking to see whether a cache your application relies on is loaded at startup.
Click Check my progress to verify the objective.
You can now check how the ready status of the Pods in the deployment corresponds to the endpoints that are actively enabled for your service. As Pods fail the readiness and liveness probe tests they are marked as not ready, their endpoints are removed from the service, and the liveness probe initiates the restart process to recover the failed pod.
The restarted pods are not marked as ready immediately and have to wait for the readiness test to pass before the service will add the endpoint back into it's pool.
You will now see that the individual pods are shown as ready. Depending on timing one or more of these might restart but it should take 2-3 minutes for that to happen. Pods that are listed as ready should have a corresponding endpoint associated with the service.
You should continue to see responses with no failures or timeouts even though individual containers are being restarted regularly due to the failures detected by the liveness probes. If all three containers restart at more or less the same time you might still see a timeout but that should rarely happen.
The combination of the liveness and readiness probes provides a way to ensure that failed systems are restarted safely while the service only forwards traffic on to containers that are known to be able to respond.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one