Skip to Content

Kubernetes Field Guide · Chapter 10 of 16

Health checks: liveness, readiness and startup probes

A running process is not the same as a working app. Probes tell Kubernetes when to send traffic, when to restart and when to wait. Get them right and deploys are invisible to users; get them wrong and probes cause the outage.

  • 30 min
  • Advanced
  • Hands-on
  • Free

By , founding engineer running Kubernetes in production. Updated .

Serviceready pods onlykubeletprobes every 10spod-1 ready ✓ live ✓pod-2 starting, not readypod-3 live ✕ restartingTraffic only goes to pod-1. pod-3 is restarted by the kubelet.
The chapter in one pictureReadiness controls traffic. Liveness controls restarts.

By the end you can

0 of 4

Running is not ready

Without probes, Kubernetes knows one thing: the process exists. It sends traffic the moment a container starts, even while the app is still loading, and it never restarts an app that is stuck but still running. Three probes fix that:

ProbeQuestionOn failure
StartupHas it finished starting?Keep waiting; the other probes are paused. Restart only if it never passes.
ReadinessCan it serve traffic right now?Remove from Service endpoints. No restart.
LivenessIs it broken beyond recovery?Restart the container.

Each probe can be an HTTP GET (any 2xx or 3xx passes), a TCP connect, a command run in the container, or a gRPC health check. By default they run every 10 seconds, time out after 1 second and act after 3 failures in a row.

Turn probes on and off and put the app in different states:

Interactive

Same app, different probes

Gets traffic?

Kubelet action

Assumes liveness checks only the process itself (/healthz) and readiness checks it can serve (/ready). Defaults: every 10s, 3 failures.

Liveness

Liveness is for one situation: the process is alive but will not recover by itself, such as a deadlock. Keep it cheap and local: an endpoint that only proves the process can respond. Be generous with timeouts, because a liveness probe that fails under load restarts pods at the worst possible moment.

Readiness

Readiness controls traffic, and it is what makes rolling updates safe: a new pod only counts as available, and an old pod is only removed, once the new one is ready. A pod can also become unready later, for example while warming a cache or when overloaded, and come back without a restart.

Step through it

A pod fails readiness, and traffic quietly moves away

  1. Kubeletruns probes
  2. ContainerGET /ready
  3. API serverpod status
  4. EndpointSliceready pod IPs
  5. kube-proxyrouting rules

Step 0 of 5

Press Play, or step through with Next.

Startup

Use a startup probe for slow starters, such as JVM apps or apps that load large models or caches. It allows failureThreshold × periodSeconds to start (30 × 5s = 150s below) and only then hands over to liveness. Before startup probes existed, people used a long initialDelaySeconds on liveness, which delays failure detection forever after.

probes.yaml
containers:
  - name: api
    image: ghcr.io/example/api:2.3.0
    ports:
      - containerPort: 8080
    startupProbe:
      httpGet: { path: /healthz, port: 8080 }
      periodSeconds: 5
      failureThreshold: 30
    livenessProbe:
      httpGet: { path: /healthz, port: 8080 }
      periodSeconds: 10
      timeoutSeconds: 3
      failureThreshold: 3
    readinessProbe:
      httpGet: { path: /ready, port: 8080 }
      periodSeconds: 5
      failureThreshold: 2
    lifecycle:
      preStop:
        sleep: { seconds: 10 }
terminationGracePeriodSeconds: 40
Up to 150s to start. Liveness and readiness wait for it.
Process-level only. timeoutSeconds 3 avoids restarts from slow replies.
Can it serve? Checked often so traffic shifts quickly.
Keep serving for 10s while endpoints and load balancers stop sending traffic.
Total time for preStop plus graceful shutdown before SIGKILL. The default is 30.

Probe mistakes that cause outages

The most common one first: a liveness probe that is less patient than the app. Tune the numbers and watch what the kubelet does over three minutes.

Interactive · Probe tuner

A slow-starting app meets your liveness probe

The rest of the list:

  • Checking dependencies in liveness. The database blips, every pod fails liveness, every pod restarts together. The outage you had becomes a bigger one.
  • Tight timeouts on liveness. Under load, replies slow down, probes time out, pods restart, the remaining pods get more load. A cascading failure caused by the safety net.
  • No readiness probe. Every deploy sends traffic to pods that are not listening yet. Users see errors on each release.
  • Using the same endpoint for both. Then readiness cannot shed load without also triggering restarts.
  • Ignoring shutdown. When a pod is deleted, it is removed from endpoints at the same time SIGTERM is sent, and load balancers take a few seconds to notice. An app that exits instantly drops those in-flight requests. Handle SIGTERM by finishing current requests, and add a short preStop sleep.

Hands-on: zero-downtime deploys

Live lab · no install

Zero-downtime with probes

Break one pod and watch it leave the Service without a single failed request.

kind-learn
  1. Tasks0/6
  2. Add a readiness probe

    web-probes.yaml checks GET / every few seconds before sending traffic.

    kubectl apply -f web-probes.yaml
    kubectl rollout status deployment/web
  3. Break readiness on one pod

    Delete the page nginx serves. The probe starts failing.

    POD=$(kubectl get pods -l app=web -o name | head -n 1)
    kubectl exec $POD -- rm /usr/share/nginx/html/index.html

    Alive but not ready: 0/1 Running. It stays up, but gets no traffic.

  4. Confirm it left the Service
    kubectl get pods -l app=web
    kubectl get endpointslices -l kubernetes.io/service-name=web
  5. Heal it by hand

    Put the page back. Readiness passes and the pod rejoins.

    kubectl exec $POD -- sh -c "echo ok > /usr/share/nginx/html/index.html"
  6. Add a liveness probe so it heals itself

    Edit web-probes.yaml in the Files tab: add a livenessProbe next to readinessProbe (httpGet path / on port 80, failureThreshold 3). Apply it.

    edit web-probes.yaml
  7. Break it again and watch the restart

    After three failed checks the kubelet restarts the container, which comes back from the image with the page restored.

    POD=$(kubectl get pods -l app=web -o name | head -n 1)
    kubectl exec $POD -- rm /usr/share/nginx/html/index.html
    kubectl get pods -l app=web

    RESTARTS went to 1 and the pod is ready again, with nobody paged.

  8. Lab complete. Keep experimenting, or press Reset to start again.
↑↓ history · Tab complete · Ctrl+C stop
Cluster map live
  • ready
  • starting / not ready
  • failing
  • terminating
Prefer your own machine? The same steps on a local cluster

Replace web with a version that has a readiness probe. Save as web-probes.yaml:

web-probes.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: nginx
          image: nginx:1.27
          readinessProbe:
            httpGet:
              path: /
              port: 80
            periodSeconds: 3
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              memory: 128Mi
Terminal
kubectl delete hpa web --ignore-not-found
kubectl apply -f web-probes.yaml
kubectl rollout status deployment/web

Break readiness on one pod by deleting the page nginx serves, and watch it leave the Service without restarting:

Terminal
POD=$(kubectl get pods -l app=web -o name | head -n 1)
kubectl exec $POD -- rm /usr/share/nginx/html/index.html
kubectl get pods -l app=web
kubectl get endpointslices -l kubernetes.io/service-name=web
NAME                   READY   STATUS    RESTARTS   AGE
web-7c5d9b8f6d-2kqvx   0/1     Running   0          2m
web-7c5d9b8f6d-h8m4n   1/1     Running   0          2m
web-7c5d9b8f6d-t6w9p   1/1     Running   0          2m
NAME        ADDRESSTYPE   PORTS   ENDPOINTS                 AGE
web-8qfzl   IPv4          80      10.244.0.31,10.244.0.32   40m
0/1 Running
Alive but not ready: no restart, no traffic.
2 endpoints
The broken pod has left the Service. Users never reach it.

Mini mission

Make liveness fix it

The broken pod above stays broken forever. Add a liveness probe so Kubernetes repairs it by itself, without breaking healthy pods during slow moments.

Reveal one safe solution

Add this under the container, next to readinessProbe, then apply and repeat the rm:

web-probes.yaml (container)
livenessProbe:
            httpGet:
              path: /
              port: 80
            periodSeconds: 10
            timeoutSeconds: 3
            failureThreshold: 3

After about 30 seconds the kubelet restarts the container, which starts from the image again with index.html back, so readiness passes and RESTARTS shows 1. Here liveness and readiness share a path only because nginx has nothing else to check; in your own apps, keep them separate.

Check yourself

Quiz

0 of 4 answered

  1. 1. A readiness probe fails. What happens?
  2. 2. An app needs 2 minutes to start. It has a liveness probe with default settings and no startup probe. What happens?
  3. 3. Why should a liveness probe not check the database?
  4. 4. Why add a short preStop sleep?

Further reading