Understanding Kubernetes: Part 34 Liveness Probe
Last updated
Last updated
📢 If you’ve been following our Kubernetes series 2025, welcome back! For new readers, check out
A Liveness Probe in Kubernetes is a diagnostic tool used to check if a pod is still running properly. It helps Kubernetes determine whether a pod is healthy and should continue running. If a pod fails its liveness probe, Kubernetes will automatically restart it to restore functionality, ensuring high availability for the application.
For example:
Imagine you have a web application running in a pod, and sometimes the application can enter an unresponsive state due to high load or a bug. By configuring a liveness probe, Kubernetes can periodically check if the application is still responding. If the liveness probe fails, Kubernetes will restart the pod, thereby minimizing downtime and ensuring the application remains available.
Liveness Probe Capabilities:
Types of Checks: Liveness probes can use HTTP requests, TCP socket connections, or execute commands to check the health of a pod.
HTTP Check: Sends an HTTP request to a specified path and expects a successful response (e.g., 200 OK).
TCP Check: Tries to establish a TCP connection on a specified port. If successful, the pod is considered healthy.
Exec Check: Executes a command inside the container. If the command succeeds (exit code 0), the pod is considered healthy.
Failure Thresholds: You can configure how many consecutive failures must occur before the pod is considered unhealthy and is restarted.
Customizability: Liveness probes can be tuned with parameters like initialDelaySeconds
, periodSeconds
, timeoutSeconds
, successThreshold
, and failureThreshold
.
In my previous role:
As a Senior DevOps Engineer, I implemented liveness probes for various microservices deployed on Kubernetes. For example, I configured a web application pod with an HTTP liveness probe to ensure that it was always responding to requests. When the application was not responding to HTTP requests, the probe would fail, and Kubernetes would automatically restart the pod, maintaining service availability. This helped us improve the overall reliability and uptime of our services.
Here’s a simple YAML for a Liveness Probe:
HTTP Liveness Probe:
In this example:
The livenessProbe
sends an HTTP GET request to the /healthz
endpoint on port 8080
of the web-container
.
The probe will start checking after a delay of 10 seconds (initialDelaySeconds
), then continue every 5 seconds (periodSeconds
).
If the probe takes longer than 2 seconds to respond, it will fail (timeoutSeconds
).
If the probe fails 3 consecutive times (failureThreshold
), Kubernetes will restart the pod.
TCP Liveness Probe:
In this example:
The livenessProbe
attempts to connect to the database on port 3306
using TCP.
It checks the pod’s health every 10 seconds, starting after an initial delay of 5 seconds.
Liveness probes are essential for ensuring that your application remains responsive and available. They automate the process of detecting and recovering from failures, reducing downtime and improving reliability in Kubernetes environments.
Take your Kubernetes journey to the next level with the Master Kubernetes: Zero to Hero course! 🌟 Whether you’re a beginner or aiming to sharpen your skills, this hands-on course covers:
✅ Kubernetes Basics — Grasp essential concepts like nodes, pods, and services. ✅ Advanced Scaling — Learn HPA, VPA, and resource optimization. ✅ Monitoring Tools — Master Prometheus, Grafana, and AlertManager. ✅ Real-World Scenarios — Build production-ready Kubernetes setups.
Don’t miss your chance to become a Kubernetes expert! 💻✨
Apply Code DEVOPS20 for 20% OFF!
🔥 Start Learning Now: [Join the Master Kubernetes Course + FREE Access to Terraform Course]()
🚀 Stay ahead in DevOps and SRE! 🔔 and never miss a beat on Kubernetes and more. 🌟
🔥 Start Learning Now: