> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Liveness vs Readiness Probes

> Explains Kubernetes liveness and readiness probes, how misconfigured probes cause cascading restarts, and how separating lightweight liveness from dependency-checking readiness prevents service interruptions.

In Kubernetes, a single misconfigured liveness probe can take an entire application offline. This guide explains how kubelet health checks work, how a common misconfiguration causes cascading failures, and the correct way to separate liveness and readiness probes so your deployment remains stable under transient dependency problems.

## How the kubelet checks health

* Each Kubernetes node runs the kubelet agent.
* The kubelet periodically asks each container a simple question: "Are you healthy?"
* A common mechanism is an HTTP GET to an application endpoint such as `/health`.
* If the kubelet does not get a successful response within the configured attempts, it assumes the container is unhealthy, kills it, and starts a new one.

This behavior can automatically recover crashed processes, but when probes include expensive or flaky checks, they can cause cascading failures across a Deployment.

## A common problematic setup (and why it fails)

* Many teams implement `/health` to include dependency checks (for example, a quick query to the database).
* Consider a backend service for a food-delivery app running in 6 identical pods, all sharing the same database.
* If the database becomes slow (temporarily overloaded for \~30 seconds), those `/health` checks that run a DB query can time out.
* The kubelet marks the pod unhealthy and restarts it.
* Restarting one pod shifts traffic to the remaining pods, increasing their load and causing their health checks to fail too — triggering more restarts in a "death spiral".

You might try to mitigate this by increasing probe timeouts or thresholds, but that usually only postpones the problem and can still fail under heavier load.

## The correct approach: separate liveness and readiness

Configure two probes within the same Pod and point them to different endpoints:

* Liveness probe -> `/health`
  * Should be extremely cheap and deterministic.
  * Only verify the process is alive and responsive (e.g., event loop, HTTP server up).
  * Must not perform expensive or flaky dependency checks (like DB queries).
  * If this probe fails, restarting the container is the right remediation.

* Readiness probe -> `/ready`
  * May perform dependency checks (database, caches, external services).
  * If this probe fails, Kubernetes removes the Pod from Service endpoints but does not kill the container.
  * When dependencies recover and `/ready` succeeds again, the Pod resumes receiving traffic.

Example Pod snippet showing both probes:

```yaml theme={null}
spec:
  containers:
    - name: backend
      image: myapp:latest
      livenessProbe:
        httpGet:
          path: /health
          port: 8080
        initialDelaySeconds: 10
        periodSeconds: 10
        timeoutSeconds: 5
        failureThreshold: 3
      readinessProbe:
        httpGet:
          path: /ready
          port: 8080
        initialDelaySeconds: 5
        periodSeconds: 5
        timeoutSeconds: 5
        failureThreshold: 2
```

* Implement `/health` as a lightweight handler that only verifies the application process is responsive.
* Implement `/ready` to include dependency checks (for example, a quick DB query or connection-pool health). When `/ready` fails, Kubernetes will stop routing traffic to that Pod but will not restart it.

![A stylized Kubernetes diagram titled "READINESS FIX" showing a service (SVC) routing traffic to multiple pods (inside a node/kubelet) while those pods make connections to a database.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Kubernetes/Liveness-vs-Readiness-Probes/kubernetes-readiness-fix-svc-pods-db.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=3d89fda292d6afef19517c0636d8eff2)

With this split:

* All six pods can quietly fail the readiness probe during the 30-second database slowdown without being restarted.
* The Service stops routing traffic to pods that are not ready, preventing overload on the remaining healthy pods.
* When the database recovers, readiness checks succeed and the pods resume receiving traffic — no restarts required.

## Quick comparison

| Probe | Purpose | What it may check | Failure behavior |
| - | - | - | - |
| Liveness | Is the process alive and responsive? | Event loop, server binding, minimal self-check | kubelet restarts the container |
| Readiness | Is the app ready to serve traffic? | Database connections, caches, external services | Pod removed from Service endpoints (no restart) |

## Best practices

* Keep liveness checks minimal and deterministic.
* Put dependency and integration checks in readiness checks.
* Use sensible `initialDelaySeconds`, `periodSeconds`, `timeoutSeconds`, and `failureThreshold` values based on your app’s startup and dependency behavior.
* Monitor probe failure metrics and logs to diagnose whether failures indicate application crashes vs. transient dependency issues.

Keep liveness checks minimal and deterministic — only check whether the process is alive and responsive. Put dependency checks (database, external services) into readiness handlers so Kubernetes can gracefully stop sending traffic without restarting containers.

Do not put expensive or flaky dependency checks inside the liveness probe. Doing so can cause cascading restarts ("death spiral") across your deployment.

## Links and references

* [Kubernetes: Configure Liveness, Readiness and Startup Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
* [Kubernetes Services and Endpoints](https://kubernetes.io/docs/concepts/services-networking/service/)
* Additional reading: strategies for graceful startup and connection pooling for backend services

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/60905e58-3a8e-4423-9743-081b4959f0a0/lesson/373b16c5-99d3-4b25-80ac-5bdd6f9ee2ed)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.