Back to Blog
Tutorials

Kubernetes Health Checks: Designing Reliable Liveness, Readiness and Startup Probes

Mustaf Abubakar
Mustaf Abubakar
•15 min read
Kubernetes Health Checks: Designing Reliable Liveness, Readiness and Startup Probes

A Kubernetes Pod can be running without being ready to serve requests. A process can also remain alive while its application has stopped making useful progress. Treating these conditions as identical often leads to unnecessary restarts, failed requests and unstable deployments.

Health checks are operational decisions, not simply indicators on a dashboard. A well-designed check tells Kubernetes whether to wait for initialization, temporarily stop routing traffic or restart a container that cannot recover on its own.

This guide uses the standard probe API documented for Kubernetes v1.37. The examples are intended for a development or staging cluster and can be adapted to a production workload after testing.

1. Understand the three health decisions

Consider a web application that takes time to load configuration, communicates with a database and processes requests using a worker pool. During initialization, it may be unable to accept requests. Later, a database outage could temporarily prevent it from serving certain operations. A deadlocked worker pool may require a restart.

These situations need different responses.

ProbeOperational questionIntended response to sustained failure
StartupHas the application initialized sufficiently?Terminate the container and apply its restart policy
ReadinessShould this instance receive service traffic?Mark it unready
LivenessIs restarting the container likely to restore progress?Terminate the container and apply its restart policy

The kubelet performs these checks. When a startup probe is configured, it postpones readiness and liveness checks until startup succeeds. In a normal Deployment, containers are restarted according to the Pod's Always restart policy.

A readiness failure does not itself restart a container. For ordinary Services, an unready Pod is excluded from regular traffic selection as the relevant endpoint information propagates. This is not an instantaneous guarantee that existing connections are drained, and specialized Service configurations can behave differently.

See the Kubernetes probe concepts for the underlying lifecycle behavior.

2. Give each health endpoint a purpose

An application can expose several inexpensive endpoints on an internal health port or on its normal application listener. Define their semantics explicitly so that future developers understand what a failing result means.

Startup: initialization completed

A startup endpoint may depend on loading essential configuration, constructing application components and completing the initialization required for other health checks to function.

Avoid making every startup check depend indefinitely on an external system that a restart cannot repair. Consider whether such a dependency should instead affect readiness.

Readiness: capacity to handle requests

A readiness endpoint should represent whether the instance can safely accept the work routed to it. For example, it may consider whether critical initialization is complete, the instance is shutting down or a necessary dependency is unavailable.

If the application can serve useful cached or read-only responses during a dependency outage, indiscriminately marking it unready might remove useful capacity. Select readiness conditions based on the service contract, not a checklist of every system the application contacts.

Liveness: recoverable through restart

A liveness endpoint should focus on local failures for which restarting the process is a reasonable corrective action. Examples include a persistent internal failure or a detected inability to make progress.

An unavailable shared database should generally not cause every application replica to fail liveness. Restarting all replicas will not repair the database, and simultaneous reconnections may make recovery harder.

There is no universal health endpoint implementation. The application team must decide which signals reflect actual service behavior and which conditions require a different response.

3. Implement a practical Deployment

The following example assumes that a team has built an HTTP application exposing /health/startup, /health/ready and /health/live on port 8080. The image reference is intentionally a placeholder. Replace it with a real image from your authorized registry that implements those endpoints.

The values illustrate a service that may take up to roughly two minutes to initialize and should tolerate brief transient failures.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-api
spec:
  replicas: 3
  minReadySeconds: 10
  progressDeadlineSeconds: 300
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  selector:
    matchLabels:
      app: example-api
  template:
    metadata:
      labels:
        app: example-api
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - name: api
          image: registry.example.invalid/example-api:1.0.0
          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
            successThreshold: 2
          livenessProbe:
            httpGet:
              path: /health/live
              port: http
            periodSeconds: 10
            timeoutSeconds: 2
            failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
  name: example-api
spec:
  selector:
    app: example-api
  ports:
    - port: 80
      targetPort: http

The nominal startup allowance is 24 checks at five-second intervals, or approximately 120 seconds. This is a sizing estimate rather than a strict wall-clock promise. Scheduling, probe execution and termination behavior affect the elapsed time.

The readiness policy uses a lower failure tolerance than liveness because removing traffic from one instance can be less disruptive than restarting it. Two successive successful readiness checks are required to mark it healthy again after failure. Startup and liveness probes must use a success threshold of one.

The deployment's rollout policy allows an extra replica while preserving the desired availability during a normal rolling update. It still requires sufficient scheduling capacity. Resource pressure, application errors and infrastructure failures can prevent the rollout from progressing.

The official Deployment documentation explains the rollout controls in more detail.

4. Choose thresholds from measurements

The example settings should not become organization-wide defaults without evidence. A fast API and a service that loads a large model have very different startup profiles.

Measure the following in an environment representative of production:

  • Initialization duration during cold starts and routine deployments.
  • Health endpoint latency during normal operation and sustained load.
  • Frequency and duration of transient dependency failures.
  • Time needed to stop accepting new work and finish active requests.

Choose a startup budget above realistic initialization times, including appropriate headroom. Set probe timeouts above ordinary health endpoint latency but low enough to detect genuinely stalled responses. Use consecutive failure thresholds to prevent a single scheduling delay from triggering an unnecessary action.

Aggressive probes can increase load and amplify a capacity incident. Conversely, excessively tolerant liveness settings can leave an irrecoverable process in service for longer than necessary. The goal is to balance recovery speed with stability.

5. Select an appropriate probe mechanism

HTTP probes suit applications that can expose explicit health semantics. Prefer simple success or failure responses with small response bodies. Avoid redirects, authentication flows and expensive business queries in the health handler.

A TCP probe is useful when the application exposes a network socket but does not implement an HTTP health endpoint. An open port alone, however, does not demonstrate that a request can complete successfully.

An exec probe can inspect local application state using a command inside the container. Avoid spawning expensive subprocesses at very short intervals, especially when running many replicas per node.

For services implementing the gRPC health protocol, a native gRPC probe is another option. Confirm the relevant version-specific configuration requirements, including port selection, before choosing it.

The Kubernetes configuration task provides examples for these mechanisms.

6. Diagnose unhealthy workloads systematically

A failed rollout is not necessarily caused by a broken application. The probe may point to the wrong port, use an incorrect path or impose a deadline that the application cannot meet.

After replacing the placeholder image and applying the manifest in a test namespace, inspect the workload:

kubectl -n demo get pods -l app=example-api
kubectl -n demo describe deployment example-api
kubectl -n demo rollout status deployment/example-api
kubectl -n demo get endpointslices \
  -l kubernetes.io/service-name=example-api

For a specific Pod, substitute its actual name:

kubectl -n demo describe pod POD_NAME
kubectl -n demo logs POD_NAME -c api
kubectl -n demo logs POD_NAME -c api --previous

The previous-container log is useful when a restart has already occurred and the previous log is still available. Pod events can reveal failed checks, image errors, scheduling problems and other conditions that require different corrective actions.

Inspect the timestamps and correlate restart counts with application logs, CPU throttling, memory pressure and dependency metrics. Do not immediately increase every timeout when a check fails. First determine whether the probe is inaccurate or is exposing a genuine application defect.

7. Design health checks for shared failures

Imagine three API replicas that all depend on the same database. The database becomes temporarily unavailable, and each replica's liveness check performs a database query. Every replica may restart while the underlying dependency remains unavailable.

A safer architecture keeps local liveness independent of that shared outage. Readiness may account for the database only if the service cannot perform useful work without it. Dependency checks should be bounded, and a cached health signal may be appropriate when checking the dependency on every request would add unnecessary load.

If all replicas become unready, users may still experience an outage. Readiness is not a substitute for redundancy, graceful degradation or capacity management. A resilient application must also define how it handles unavailable dependencies, including timeouts, backoff and safe error responses.

The same distinction applies to background consumers and scheduled workers. An HTTP readiness check alone does not stop a worker from consuming messages. The worker must implement its own pause, shutdown and work-claim behavior when necessary.

8. Validate behavior before production

Use a controlled test environment and document the expected result of each exercise.

ScenarioExpected behavior
Slow initialization within the startup budgetContainer is given time to initialize
Temporary readiness failureInstance becomes unready without a restart
Persistent local liveness failureContainer restarts
Shared dependency outageNo unnecessary fleet-wide liveness restart
New release fails readinessRollout does not advance as if the new Pods were available
Application shuts downNew work is stopped and existing work is handled according to the application's shutdown policy

A failed progress deadline reports that the Deployment has not progressed; it does not automatically roll back the release. Use an authorized deployment controller or an operational runbook to decide when rollback is appropriate.

Track probe failures, container restarts, unavailable replicas, rollout duration, request errors and latency. Alert on meaningful patterns rather than treating every transient check failure as an incident.

Conclusion

Reliable Kubernetes health checks begin with a precise distinction between startup, traffic eligibility and process recovery. Separate the three decisions, make probe handlers inexpensive, calibrate thresholds from real workload behavior and test failure scenarios before deployment.

A healthy-looking Pod is not proof of a healthy service. Combine probes with application observability, sound rollout policies and tested dependency-failure handling to improve service reliability.

References and further reading

Comments

No comments yet

Be the first to share your thoughts!

Leave a Comment

Your email will not be published

0/1000 characters

Want to work together?

I'm always open to discussing new projects and opportunities.

Get in Touch