Skip to main content
This lesson explains how to implement and validate readiness and liveness probes on your Kubernetes web application. Follow along as we inspect your deployment, test with HTTP requests, scale your application, and configure probes to ensure only healthy pods receive traffic and that failing pods are automatically recovered.

1. Inspecting the Initial Deployment

To begin, verify that your application is running by inspecting the pods and services in your cluster. Execute the following commands:
Opening the web portal via the Kubernetes dashboard confirms that the application is accessible.

2. Testing the Application with a Script

A provided test script (curl-test.sh) sends HTTP requests to verify the web server’s response. Run the script as shown below:
At this stage, only one pod (simple-webapp-1) is handling the traffic.

3. Scaling Up: Adding a Second Pod

To improve scaling, a second pod (simple-webapp-2) is introduced. Run the test script again to observe the behavior:
Here, although simple-webapp-1 responds correctly, some requests to simple-webapp-2 fail because it is receiving traffic even though it’s not yet ready.
The readiness probe will ensure that a pod only receives traffic when it is ready, preventing failed requests.

4. Configuring a Readiness Probe for Pod Two

To stop the failed requests, configure a readiness probe for simple-webapp-2. This probe sends an HTTP GET request to the /ready endpoint on port 8080.
  1. Export the current configuration of simple-webapp-2:
  2. Delete the existing pod to prepare for the updated configuration:
  3. Edit the webapp2.yaml file to include the readiness probe under the container configuration. Insert the following snippet:
    Below is an example configuration for simple-webapp-2:
  4. Re-deploy the updated pod configuration:
Verify the effectiveness of the readiness probe by watching the status of your pods.

5. Verifying Load Balancing After Applying the Readiness Probe

Re-run the test script to ensure that traffic is now only directed to pods that are ready. Initially, traffic might still be sent to simple-webapp-1, but once simple-webapp-2 becomes ready, load balancing will occur:
At this point, traffic is successfully balanced between the two pods.

6. Simulating a Pod Crash

To understand the behavior when a pod fails, a crash script (crash-app.sh) is provided to simulate a failure in simple-webapp-2:
After running the crash script, check the pods using:
The test script (curl-test.sh) will temporarily show that requests are routed only to simple-webapp-1 until Kubernetes restarts the crashed pod automatically.
When a pod crashes, Kubernetes automatically restarts it; however, during the downtime, ensure that your application can handle the temporary loss of a pod.

7. Implementing a Liveness Probe to Handle Freezing

In this final section, you will configure a liveness probe to automatically recover pods that become unresponsive (frozen).

Update the Configuration for Both Pods

  1. Export the current configuration for your pods:
  2. Delete all existing pods to redeploy them with the new liveness probe configuration:
  3. Open the webapp.yaml file and insert the liveness probe under the container specification for each pod. For example, for simple-webapp-1, add:
    The full configuration for simple-webapp-1 might look like this:
    Similarly, update the configuration for simple-webapp-2 as follows:
  4. Redeploy the updated configuration:

Test the Liveness Probe

Simulate a pod freeze by executing the freeze script:
Then, use the test script (curl-test.sh) to observe how traffic is affected. Finally, check the pod statuses:
You should notice that Kubernetes restarts the frozen pod automatically, ensuring continuous service availability.

Summary

  • The readiness probe ensures that only pods that are ready receive traffic.
  • The liveness probe automatically restarts pods that become unresponsive or frozen.
By following these configurations, you enhance the overall availability and reliability of your Kubernetes-deployed applications. Happy deploying!

Watch Video