Kubernetes Health Check Design: Preventing Outages with Startup, Readiness, and Liveness Probes

Kubernetes Health Check Design: Preventing Outages with Startup, Readiness, and Liveness Probes

A Kubernetes container being in the Running state does not mean that the application is ready to serve traffic. The process may still be loading configuration, establishing database connections, rebuilding an in-memory cache, or performing another long initialization task. Poorly designed health checks fail to distinguish these states and create two common production problems: traffic reaches Pods that are not ready, or healthy containers are repeatedly restarted because of a temporary dependency failure.

Kubernetes provides three main probe types: startup probes, readiness probes, and liveness probes. They are not interchangeable. Each one answers a different operational question, and using the wrong probe for a condition can turn a recoverable problem into an outage.

What question does each probe answer?

ProbeQuestionEffect of failure
StartupHas the application completed initialization?The container can be considered unhealthy and restarted.
ReadinessCan this Pod safely receive traffic right now?The Pod is removed from matching Service endpoints while the container keeps running.
LivenessIs the process running but stuck or unable to recover?The kubelet restarts the container.

Readiness is intended to remove a Pod from traffic, not to terminate it. Liveness is intended for conditions such as a deadlock or an unrecoverable process state. When a startup probe is configured, Kubernetes does not run liveness and readiness probes until startup succeeds. That allows slow-starting applications to have a separate initialization budget without weakening their steady-state liveness policy.

The common mistake: one /health endpoint for everything

Many applications expose a single endpoint that checks the process, the database, the cache, and several third-party services at the same time. This seems convenient, but it mixes different operational decisions.

Suppose the database becomes unavailable for 30 seconds. It may be correct for readiness to fail because new requests should not be routed to that Pod. Connecting the same check to liveness is dangerous. If every Pod fails liveness because the database is down, Kubernetes may restart all of them. The application does not recover; instead, it enters a restart loop and creates additional connection pressure when every new process tries to reconnect.

A safer design separates the endpoints by responsibility:

  • Liveness: Verifies that the process and its basic execution loop can still respond.
  • Readiness: Verifies that the application can currently perform its required work.
  • Startup: Represents long initialization such as loading a large configuration, warming a cache, or preparing application state.

Example Deployment configuration

The following Deployment assumes that the application exposes three HTTP endpoints: /health/startup, /health/ready, and /health/live. The exact paths are application-specific; the important part is the separation of responsibilities.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders-api
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  selector:
    matchLabels:
      app: orders-api
  template:
    metadata:
      labels:
        app: orders-api
    spec:
      terminationGracePeriodSeconds: 45
      containers:
      - name: api
        image: example/orders-api:2026.11
        ports:
        - name: http
          containerPort: 8080
        startupProbe:
          httpGet:
            path: /health/startup
            port: http
          periodSeconds: 5
          timeoutSeconds: 2
          failureThreshold: 24
        readinessProbe:
          httpGet:
            path: /health/ready
            port: http
          periodSeconds: 5
          timeoutSeconds: 2
          failureThreshold: 2
        livenessProbe:
          httpGet:
            path: /health/live
            port: http
          periodSeconds: 10
          timeoutSeconds: 2
          failureThreshold: 3

This configuration allows roughly two minutes for startup failures to be evaluated. After the startup probe succeeds, readiness and liveness become active. Two consecutive readiness failures can remove the Pod from service traffic, while three liveness failures can trigger a restart.

These numbers are examples, not universal defaults. They should be derived from observed startup and response times. A probe should be calibrated against production behavior rather than configured only to produce a convenient green status.

What should readiness check?

A readiness endpoint should not attempt to prove that the entire distributed system is perfect. It should answer whether this Pod can safely process requests at this moment. Depending on the application, it may check:

  • Whether required configuration has been loaded.
  • Whether a critical database connection pool is available.
  • Whether mandatory local components such as a message consumer or cache are initialized.
  • Whether the application has entered a controlled shutdown state.

Adding every external dependency to readiness requires care. A temporary outage at a payment provider may not justify removing every API replica from traffic. The application might instead return a controlled error for payment operations while continuing to serve unrelated requests. Readiness decisions should reflect business behavior, not just infrastructure topology.

Why liveness should be lightweight

Liveness probes run repeatedly, and their failure can cause a destructive action. Avoid expensive SQL queries, remote API calls, and large file scans in the liveness endpoint. A lightweight in-process check is usually safer.

Liveness is useful for detecting a process that appears to be running but cannot make progress. Examples include a deadlocked event loop, a stopped worker, or a process that no longer responds to requests. If the process has already crashed, Kubernetes can often handle it through the container restart policy; liveness does not need to detect every possible failure.

Combine probes with graceful shutdown

When a Pod is terminated, the application should stop accepting new work and receive enough time to complete in-flight requests. The application should handle SIGTERM, stop admission of new work, drain active requests, and close connections. terminationGracePeriodSeconds defines the maximum time available for that process.

A practical shutdown sequence looks like this:

  1. The Pod enters termination.
  2. The application receives the shutdown signal and makes readiness fail.
  3. The Service stops routing new traffic to the Pod.
  4. Existing requests are allowed to complete.
  5. The process exits before the grace period expires.

The readiness endpoint must understand the shutdown state. Otherwise, the application may continue accepting new requests while it is already preparing to exit.

Common mistakes and troubleshooting steps

  • Using one endpoint for all three probes: This hides the difference between “not ready” and “must be restarted.”
  • Allowing too little startup time: Large applications may enter repeated restart loops. Check probe events in kubectl describe pod.
  • Skipping readiness: New or partially initialized Pods may receive traffic too early.
  • Making liveness depend on external services: A dependency outage can become a restart storm.
  • Restarting after one transient failure: Short network delays and CPU pressure can create false positives.

During an incident, inspect kubectl get pods, kubectl describe pod, container logs, and restart reasons together. Measure probe latency and failure counts as well. Health checks are not merely Kubernetes YAML; they are part of the application’s runtime contract.

Implementation checklist

  1. Define separate responsibilities for startup, readiness, and liveness.
  2. Use readiness for traffic admission and liveness for unrecoverable process health.
  3. Use a startup probe for long or variable initialization.
  4. Avoid expensive remote calls in probe handlers.
  5. Make readiness fail during graceful shutdown.
  6. Validate that the rolling update strategy keeps a healthy replica available.
  7. Set timeouts and thresholds from observed startup and response-time data.
  8. Monitor probe failures, restart counts, and termination reasons.

Good health-check design does more than answer whether a Pod is “healthy.” It defines when traffic may be accepted, when isolation is enough to contain a fault, and when restarting a process is genuinely necessary. Once those decisions are separated, rolling updates become safer, temporary dependency failures become less destructive, and production behavior becomes easier to reason about.

Sources

//

0 Comments

Write Comment

E-Mail address will not be published