Kubernetes Tutorial · Configuration and Resources · Lesson 20 of 26

Liveness, Readiness and Startup Probes

Tell Kubernetes when a container is ready for traffic, when it's stuck, and when it's still starting.

Create a free account to save this page, take notes and track your progress. Sign in

Three probes

Probe Failing means Effect
readiness Not ready to serve Removed from Service endpoints (not restarted)
liveness Stuck or broken Container restarted
startup Still starting Liveness and readiness wait until it succeeds

Probes can be HTTP (httpGet), TCP (tcpSocket), gRPC or a command (exec).

Common mistakes: a liveness probe that checks dependencies (a database outage then restarts every pod), and liveness probes on slow-starting apps without a startup probe (restart loops).

Readiness controls traffic, not restarts
kubectl create namespace demo-probes > /dev/null
trap 'kubectl delete namespace demo-probes --wait=false > /dev/null' EXIT
cat > pod.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata: {name: app, labels: {app: app}}
spec:
  containers:
    - name: app
      image: busybox:1.37
      command: ["sh", "-c", "sleep 3600"]
      readinessProbe:
        exec: {command: ["test", "-f", "/tmp/ready"]}
        periodSeconds: 1
EOF
kubectl -n demo-probes apply -f pod.yaml > /dev/null
kubectl -n demo-probes expose pod app --port=80 > /dev/null
kubectl -n demo-probes wait --for=jsonpath='{.status.phase}'=Running pod/app --timeout=120s > /dev/null
ready() { kubectl -n demo-probes get pod app -o jsonpath='{.status.containerStatuses[0].ready}'; }
eps() { kubectl -n demo-probes get endpointslices -l kubernetes.io/service-name=app -o jsonpath='{.items[0].endpoints[0].conditions.ready}'; }
sleep 3; echo "before /tmp/ready: ready=$(ready), endpoint ready=$(eps)"
kubectl -n demo-probes exec app -- touch /tmp/ready
sleep 3; echo "after /tmp/ready:  ready=$(ready), endpoint ready=$(eps)"
echo "restarts: $(kubectl -n demo-probes get pod app -o jsonpath='{.status.containerStatuses[0].restartCount}') (failing readiness never restarts a container)"

Output

before /tmp/ready: ready=false, endpoint ready=false
after /tmp/ready:  ready=true, endpoint ready=true
restarts: 0 (failing readiness never restarts a container)

Run this on your computer — see “Get Started” for setup.

Test yourself

Should a liveness probe check that the database is reachable?

  1. Yes, always
  2. No: a database outage would restart every pod; check only the process itself
  3. Only for StatefulSets
  4. Only on startup
Show answer

Answer: No: a database outage would restart every pod; check only the process itself

Dependency checks belong in readiness at most, and even there with care.

Was this page helpful?