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: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:
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: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.
-
Export the current configuration of simple-webapp-2:
-
Delete the existing pod to prepare for the updated configuration:
-
Edit the
webapp2.yamlfile to include the readiness probe under the container configuration. Insert the following snippet:Below is an example configuration for simple-webapp-2: -
Re-deploy the updated pod configuration:
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: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:
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
-
Export the current configuration for your pods:
-
Delete all existing pods to redeploy them with the new liveness probe configuration:
-
Open the
webapp.yamlfile 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: -
Redeploy the updated configuration:
Test the Liveness Probe
Simulate a pod freeze by executing the freeze script:curl-test.sh) to observe how traffic is affected. Finally, check the pod statuses:
Summary
- The readiness probe ensures that only pods that are ready receive traffic.
- The liveness probe automatically restarts pods that become unresponsive or frozen.