Appearance

Probes and graceful recovery

Choose probes for slow startup, traffic eligibility, and hung processes, then trace how a Pod shuts down.

What you will understand

  • Match startup, readiness, and liveness probes to the outcomes they control.
  • Interpret Pod readiness and container restart counts in a lab.
  • Explain how application shutdown uses the Pod’s termination grace period.

Builds on: Rolling updates and rollback

Which probe answers which question

Imagine an application with a long startup, an occasional failed connection to a dependency, and a bug that can freeze its request handler. The kubelet uses a probe to test a container. Each probe has a different consequence, so decide what should happen after a check fails before you decide what the check should test.

A startup probe gives an application time to initialize. While this probe has yet to succeed, the kubelet holds back readiness and liveness probing. If startup failures reach the configured threshold, the kubelet terminates the container and the restart policy applies.

A readiness probe asks whether the application can accept traffic now. After repeated failures, the Pod becomes unready and normal Service routing excludes it. The container can continue running and regain readiness. A liveness probe asks whether the container should be restarted to recover. If liveness fails repeatedly, the kubelet stops the container and handles restart according to policy. Try each failure in the scene and watch which state changes.

Three probes, three outcomes

Startup delays the other checks, readiness changes traffic eligibility, and liveness can cause a restart.

  1. Startup allows time to initialize

    The startup probe runs while initialization proceeds. Readiness and liveness wait until it succeeds. Reaching its consecutive failure threshold makes the kubelet terminate and restart this container under the assumed Always policy.

  2. Readiness gates new traffic

    After startup succeeds, readiness can mark the Pod unready. The process stays running and endpoint readiness is updated asynchronously.

  3. Liveness can request a restart

    If liveness repeatedly fails beyond tolerance, the kubelet terminates and restarts this container under its restart policy. This is local recovery, not a new Pod UID.

One ordinary container uses Always restart policy; Service routing behavior is the normal non-publishNotReadyAddresses case.

Inspect what each probe changes

Follow one web Pod through startup, a temporary readiness failure, and a separate liveness failure. Its Service has a second healthy backend.

1 / 5

From KubeletTo Web container

Startup succeeds

The kubelet has been running only the configured startup probe. After it passes, the kubelet can run readiness and liveness checks on their own schedules. Readiness soon passes and the Pod starts receiving traffic.

Readiness and liveness checks
Before
Waiting for the startup probe
After
Both can run
Startup succeeds

The kubelet has been running only the configured startup probe. After it passes, the kubelet can run readiness and liveness checks on their own schedules. Readiness soon passes and the Pod starts receiving traffic.

The startup probe is from the lesson example. The lab uses separate readiness and liveness checks. Probe intervals and delays between API updates are compressed.

If a dependency goes offline but your web process can recover on its own, which check should usually fail?
Reveal prediction answer

Readiness can take the Pod out of ordinary Service traffic while the dependency recovers. Repeated liveness failures restart the container, which may accomplish nothing during a dependency outage.

Record the Pod UID and restart count before removing its readiness file. Compare those fields with the Pod Ready and EndpointSlice ready conditions after the failure.

Verify readiness in the probe and rollout lab
Explore another case

Open Inspect what each probe changes to compare the Pod’s Ready condition, its endpoint’s ready condition, and the container’s restart count. They tell you which part of the system changed and which check caused it.

Configure the three HTTP checks

Save this example as probes-demo.yaml. All three probes use the same HTTP path here so you can focus on how their timing and consequences differ. The named port http resolves to port 80. The startup probe’s two-second period and 30-failure threshold give the process roughly a minute to start. In a real application, separate endpoints may check different things. For example, an app might report unready while a required backend is down but still report live because restarting it would achieve nothing.

apiVersion: v1
kind: Pod
metadata:
  name: probes-demo
spec:
  terminationGracePeriodSeconds: 30
  containers:
    - name: web
      image: nginx:1.27.5
      ports:
        - name: http
          containerPort: 80
      startupProbe:
        httpGet:
          path: /
          port: http
        periodSeconds: 2
        failureThreshold: 30 # Roughly a 60-second startup window, not an SLA.
      readinessProbe:
        httpGet:
          path: /
          port: http
        periodSeconds: 5
        failureThreshold: 2
      livenessProbe:
        httpGet:
          path: /
          port: http
        periodSeconds: 10
        failureThreshold: 3
      lifecycle:
        preStop:
          exec:
            command: ["/bin/sh", "-c", "nginx -s quit"]

After applying the file, note READY and RESTARTS in the watch. The describe output reports failed probes in Events when failures occur. Record the restart count as a baseline for a later failure.

kubectl apply -f probes-demo.yaml
kubectl get pod probes-demo -w
kubectl describe pod probes-demo
kubectl get pod probes-demo -o jsonpath='{.status.containerStatuses[0].restartCount}'

Follow a Pod through shutdown

When you delete the Pod, graceful termination gives the application a bounded time to stop. The kubelet runs the preStop hook in this example, which asks nginx to shut down gracefully. The hook uses part of the 30-second period. During termination, the endpoint is marked terminating and stops receiving normal new Service traffic as the change propagates. Connections already established can continue until the application closes them or the grace period expires. Step through both routing and process shutdown in the scene.

What happens when you delete a serving Pod?

Routing updates and process shutdown proceed asynchronously. The application has a bounded time to finish its work.

  1. API serverRecord the deletion request
    EndpointSlice controller and kubeletThe endpoint begins leaving normal routing while the kubelet begins shutdown.
  2. KubeletRun the hook and signal the process
    ApplicationThe hook and shutdown share the termination grace period.
  3. ApplicationFinish or close open requests
    Client connectionsThe process exits or is stopped when its time expires.
Follow the sequence

Routing updates and process shutdown proceed asynchronously. The application has a bounded time to finish its work.

Traffic propagation and kubelet termination happen concurrently; default graceful deletion is shown.

Use the probe and recovery lab to make a Pod unready and confirm that its container stays running. In the shutdown exercise, watch the endpoint change while a Pod is still shutting down.

Choose failures that justify a restart

A service with a failing shared dependency can lose every replica if the liveness check restarts all the containers. Give slow startup its own budget and scope liveness to failures a restart can fix. A long-lived connection can outlast an endpoint’s readiness change, so the application still needs a plan for finishing or closing active requests.

Check your understanding

A Pod’s ready count goes to zero while the restart count stays flat. Which probe could explain that?

Readiness can make the Pod ineligible for normal Service traffic while the running container stays in place. Look at the Pod conditions and probe-related events to confirm the cause. The restart count helps distinguish this case from a liveness failure.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu