How to Add Liveness and Readiness Probes to a Kubernetes Deployment

Kubernetes probes are the difference between 'the pod is running' and 'the app is actually serving.' A readinessProbe stops traffic from reaching a pod before it's ready; a livenessProbe restarts it when it hangs. Here's how to add both to a Deployment.

Kubernetes Engineerkuberneteskubectlprobes

What each probe does

Kubernetes ships two health-check hooks on every container:

Without these probes, every pod gets traffic the instant it starts (before the app is up), and a deadlocked process sits there forever instead of being recycled.

Adding probes to a Deployment

Both probes go inside the container spec. For an HTTP server listening on port 80:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: nginx:1.27-alpine
        ports:
        - containerPort: 80
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 3
          periodSeconds: 5
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 10
          periodSeconds: 10

Apply and verify the rollout completes cleanly:

kubectl apply -f deployment.yaml
kubectl rollout status deployment/web

Tuning the timing parameters

Getting initialDelaySeconds wrong is the most common probe mistake:

Other probe types

httpGet is the most common, but Kubernetes supports two others:

A dedicated /healthz or /ready endpoint (separate from your main routes) is better than probing / in production - it lets you signal readiness independently of serving actual requests.

Want to try it hands-on? HeyDevJob gives you this exact setup in a live cloud workspace in your browser - edit it, run it, and see it work. Free, nothing to install.

Try it in a workspace →

What you'll practice

FAQ

What is the difference between a liveness probe and a readiness probe in Kubernetes?

A readiness probe controls traffic routing - a pod that fails readiness is removed from the Service endpoint list so it receives no requests. A liveness probe controls restarts - a pod that fails liveness is killed and restarted by kubelet. You usually want both: readiness to gate traffic, liveness to recover hung processes.

What happens if I don't add probes to a Kubernetes Deployment?

Without a readiness probe, Kubernetes sends traffic to a pod the moment it starts, before the app is ready to serve, causing request errors during deploys. Without a liveness probe, a hung or deadlocked process is never restarted - the pod stays Running but serves nothing.

Why is my pod restarting in a loop after I added a liveness probe?

The most common cause is an initialDelaySeconds that is too short. The liveness probe fires before the app finishes starting, the check fails, and Kubernetes restarts the container - repeating forever. Increase initialDelaySeconds to exceed your app's actual startup time.

What are liveness and readiness probes?

A readiness probe decides whether a pod should receive traffic; a liveness probe decides whether a hung pod should be restarted. Readiness gates the Service endpoints; liveness triggers a container restart.

Keep learning

Fix a Kubernetes CrashLoopBackOffKubernetes projectHeal a Kubernetes Service With No EndpointsKubernetes projectFix a Kubernetes ImagePullBackOffKubernetes projectKubernetes roadmapStep by step to hiredKubernetes interview questionsSTAR answersAll Kubernetes projectsProjects hub

Learn it by doing. Open this in a live cloud workspace, make the change yourself, and keep a record of the work you can share.

Open the workspace →