Understanding Liveness and Readiness Probes in Kubernetes β€” Complete Guide


🩺 Understanding Liveness and Readiness Probes in Kubernetes β€” Complete Guide

In Kubernetes, your applications don’t just run. They’re continuously watched, checked, and healed by the system itself.

This self-monitoring capability is powered by Liveness and Readiness Probes β€” vital for keeping containers healthy and available.

Think of them like a nurse and a receptionist at a clinic:

  • One checks if you’re alive (Liveness)
  • The other decides if you’re ready to see patients (Readiness)

Let’s break it down from the ground up β€” with examples and real-world use cases.


🚦 What Are Probes in Kubernetes?

A probe is a Kubernetes mechanism to check the health or status of a container. Kubernetes uses these checks to decide whether to:

  • Restart a container
  • Wait before routing traffic
  • Keep a pod in service

K8s uses three types of probes:

Probe TypePurpose
LivenessChecks if the container is still running and should be restarted
ReadinessChecks if the app is ready to serve traffic
Startup (Optional)Checks if the app has finished starting (used with slow boot apps)

🧬 Liveness Probe – “Is the container alive?”

Purpose:

If the liveness probe fails, Kubernetes will restart the container. This helps recover from crashes or deadlocks where the container looks fine (running), but is internally frozen.

Real-World Analogy:

A nurse walks into the room and checks if the patient has a pulse. If not β€” call emergency services (restart the pod).

Example (YAML):

livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 5
  failureThreshold: 3

Configuration Explained:

  • httpGet: Hits the /healthz endpoint
  • initialDelaySeconds: Wait 10s before starting checks
  • periodSeconds: Check every 5s
  • failureThreshold: 3 consecutive failures trigger a restart

🟒 Readiness Probe – “Is the container ready to receive traffic?”

Purpose:

If the readiness probe fails, Kubernetes removes the pod from the service endpoint list β€” without restarting it.

This helps during:

  • App initialization
  • Temporary downtime (e.g., DB not ready)

Real-World Analogy:

The receptionist checks if the doctor is ready to see patients. If not, they hold the queue β€” not call the ambulance.

Example (YAML):

readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 3

πŸ”§ Probe Types

TypeHow it works
httpGetSends HTTP GET to a path
tcpSocketChecks if TCP port is open
execRuns a shell command (e.g., curl, ps aux)

Example – exec:

livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 10

🧠 Advanced Use Cases & Best Practices

1. Separate Liveness and Readiness

Don’t use the same endpoint for both. Why?

  • Liveness failure causes a restart
  • Readiness failure just removes from load balancer

πŸ‘‰ Example:

  • /healthz β†’ deep checks (DB connection, cache)
  • /ready β†’ shallow checks (service responsive?)

2. Avoid Premature Restarts

Use appropriate initial delay and failure thresholds, especially for:

  • Slow boot apps
  • Apps with warm-up routines

Bad config = too many restarts = crashing apps


3. Use Startup Probes for Monoliths

For apps that take a long time to start, use startupProbe to delay liveness checks until fully started.

startupProbe:
  httpGet:
    path: /start
    port: 8080
  failureThreshold: 30
  periodSeconds: 10

4. Don’t Abuse Exec Probes

Running shell commands inside containers:

  • Consumes CPU
  • Can fail if shell tools are missing
  • Use httpGet for web apps, tcpSocket for basic checks

5. Testing Your Probes

Simulate failures with:

  • Kill the health endpoint temporarily
  • Monitor restarts via kubectl describe pod and logs
  • Use kubectl get endpoints to verify readiness

πŸ” Monitoring & Observability

Track probe failures via:

  • kubectl describe pod
  • Events in logging tools
  • Prometheus metrics via exporters (e.g., kube-state-metrics)

🏁 Final Summary: Choosing the Right Probe

ScenarioUse
App might hang or deadlockLiveness Probe
App takes time to initializeReadiness + Startup Probe
App temporarily loses DB connectionReadiness Probe only
App returns 200 OK but has internal issuesUse deep readiness checks
Stateless microserviceLiveness + Readiness (default combo)

πŸš€ Final Thoughts

Probes are one of the most powerful β€” yet often misunderstood β€” features in Kubernetes.

Used correctly, they:

  • Save your pods from unnecessary restarts
  • Protect your users from broken apps
  • Boost uptime and resilience

In the world of Kubernetes, probes are the heartbeat of healthy apps.


Related Posts

Kubernetes RBAC cookbook: common roles (dev, SRE, read-only) safely

Kubernetes RBAC is one of those things that feels annoying until the day it saves your cluster from β€œoops, I deleted prod.” The tricky part isn’t what…

Read More

General Build Pipeline (CI) in Azure DevOps

Let’s walk through a general-purpose Azure DevOps build pipeline template that can be applied to most common application types (web apps, APIs, microservices, etc.) using CI/CD best…

Read More

Kubernetes Certifications in 2025: Which One Should You Choose?

Kubernetes Certifications in 2025: Which One Should You Choose? Kubernetes has become the cornerstone of modern cloud-native application deployment and orchestration. Whether you’re a beginner just diving…

Read More

Top 5 Kubernetes Tools That Will Replace Your Bash Scripts in 2025

πŸš€ Top 5 Kubernetes Tools That Will Replace Your Bash Scripts in 2025 For years, DevOps engineers and platform teams have relied on Bash scripts to automate…

Read More

Kubernetes Horror Stories (and What We Learned From Them)

☠️ Kubernetes Horror Stories (and What We Learned From Them) Because what doesn’t kill your cluster makes it stronger. Kubernetes is powerful β€” but with great power…

Read More

Why Your Kubernetes Costs Are Out of Control – and How to Fix It (2025 Guide)

πŸ’Έ Why Your Kubernetes Costs Are Out of Control – and How to Fix It (2025 Guide) Kubernetes is powerful β€” but it isn’t cheap. While it…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x