Introduction
In Kubernetes, keeping your application healthy and available is very important. Kubernetes provides built-in features called liveness probes and readiness probes to monitor the health of your containers.
A liveness probe checks whether your application is still running properly. If it fails, Kubernetes will restart the container automatically.
A readiness probe checks whether your application is ready to receive traffic. If it fails, Kubernetes will temporarily stop sending requests to that container.
In simple terms:
Liveness Probe = "Is the app alive?"
Readiness Probe = "Is the app ready to serve users?"
These probes are essential for building reliable, scalable, and production-ready applications in Kubernetes.
Detailed Explanation with Examples
Liveness Probe
A liveness probe ensures your application is not stuck or crashed internally.
Example scenario:
Your app is running but stuck in an infinite loop
It is not responding to requests
Kubernetes will detect this using a liveness probe and restart the container.
Readiness Probe
A readiness probe ensures your application is fully ready before handling traffic.
Example scenario:
Your app is starting and loading data
It is not ready yet
Kubernetes will wait until the readiness probe passes before sending traffic.
Types of Probes in Kubernetes
Kubernetes supports three main types of probes:
HTTP Probe
Checks an HTTP endpoint of your application.
TCP Probe
Checks if a specific port is open.
Command (Exec) Probe
Runs a command inside the container to check health.
Step-by-Step Configuration
Step 1: Create a Deployment YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app-image
Step 2: Add Liveness Probe
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 10
periodSeconds: 5
Explanation:
initialDelaySeconds: Wait before first check
periodSeconds: How often to check
Step 3: Add Readiness Probe
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Explanation:
Kubernetes sends traffic only when this probe succeeds
Step 4: Full Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app-image
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Real-Life Examples and Scenarios
Scenario 1: Application Crash Recovery
If your application crashes silently:
Liveness probe detects failure
Kubernetes restarts the container automatically
Scenario 2: Slow Startup Applications
Some applications take time to start.
Readiness probe prevents traffic until ready
Avoids user-facing errors
Scenario 3: Rolling Updates
During deployments:
Readiness probe ensures only healthy pods receive traffic
Helps achieve zero downtime deployment
Real-World Use Cases
Microservices running in Kubernetes clusters
High-availability systems (banking, e-commerce)
APIs deployed on cloud platforms (AWS, Azure, GCP)
CI/CD pipelines with automated deployments
Advantages and Disadvantages
Advantages
Improves application reliability
Enables automatic recovery
Supports zero downtime deployments
Prevents sending traffic to unhealthy containers
Disadvantages
Incorrect configuration can cause restarts
Adds complexity to deployment setup
Requires proper health endpoints in application
Comparison Table
| Feature | Liveness Probe | Readiness Probe |
|---|---|---|
| Purpose | Check if app is alive | Check if app is ready |
| Action on Failure | Restart container | Stop traffic temporarily |
| Use Case | Crash or deadlock detection | Startup and traffic control |
| Impact | Restarts pod | Removes pod from service |
Summary
Kubernetes liveness and readiness probes are essential tools for managing container health and ensuring high availability in modern cloud-native applications. Liveness probes help automatically recover from failures by restarting unhealthy containers, while readiness probes ensure that only fully prepared applications receive user traffic. By configuring these probes correctly, developers can build reliable, scalable, and production-ready systems with minimal downtime and better user experience.

Join the conversation! Your thoughts help the community grow.