0
0
Kubernetesdevops~30 mins

Probe failure and container restart behavior in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Probe failure and container restart behavior
📖 Scenario: You are managing a Kubernetes cluster running a simple web application. You want to understand how Kubernetes handles container health checks and restarts when probes fail.
🎯 Goal: Learn how to configure liveness and readiness probes in a Kubernetes Pod manifest and observe container restart behavior when probes fail.
📋 What You'll Learn
Create a Pod manifest with a container running the nginx image
Add a liveness probe that checks the HTTP endpoint /healthz on port 80
Add a readiness probe that checks the HTTP endpoint /ready on port 80
Simulate probe failure by using incorrect probe paths
Observe and print the Pod status to see container restart behavior
💡 Why This Matters
🌍 Real World
Kubernetes uses probes to check if containers are healthy and ready to serve traffic. Understanding probe failures helps keep applications stable.
💼 Career
DevOps engineers and site reliability engineers configure probes to automate container health checks and manage restarts, improving uptime.
Progress0 / 4 steps
1
Create a basic Pod manifest with nginx container
Create a Kubernetes Pod manifest named nginx-pod.yaml with a single container named nginx using the image nginx:latest. The container should expose port 80.
Kubernetes
Need a hint?

Use apiVersion: v1 and kind: Pod. Define metadata.name as nginx-pod. Under spec.containers, add one container named nginx with image nginx:latest and expose port 80.

2
Add liveness and readiness probes with incorrect paths
Add a livenessProbe and a readinessProbe to the nginx container. Both probes should use httpGet on port 80. Set the livenessProbe path to /healthz and the readinessProbe path to /ready. Use default probe settings for initial delay and period.
Kubernetes
Need a hint?

Under the container spec, add livenessProbe and readinessProbe sections. Use httpGet with path and port fields. Use paths /healthz and /ready respectively.

3
Apply the Pod manifest and observe container restart behavior
Apply the Pod manifest using kubectl apply -f nginx-pod.yaml. Then use kubectl get pods nginx-pod -o jsonpath='{.status.containerStatuses[0].restartCount}' to check the container restart count. Write a command to get the restart count.
Kubernetes
Need a hint?

Use kubectl apply -f nginx-pod.yaml to create the Pod. Then use kubectl get pods nginx-pod -o jsonpath='{.status.containerStatuses[0].restartCount}' to see how many times the container restarted.

4
Fix probe paths and verify no restarts
Edit the Pod manifest to change the livenessProbe and readinessProbe paths to / (root path). Apply the updated manifest with kubectl apply -f nginx-pod.yaml. Then print the restart count again using kubectl get pods nginx-pod -o jsonpath='{.status.containerStatuses[0].restartCount}'. Write the command to print the restart count.
Kubernetes
Need a hint?

Change both probe paths to / which is a valid path for nginx. Apply the manifest again and check the restart count. It should not increase if probes succeed.