Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 258 of 8024. Kubernetes Architecture and Core ObjectsFree lesson

Implementing Pod Health Probes

You will configure liveness, readiness, and startup probes to automate the monitoring and self-healing behavior of your application containers.

In this lesson, you will learn how to configure liveness, readiness, and startup probes to automate the monitoring and self-healing behavior of your application containers.

In a distributed system, processes don't just stay "up"—they can freeze, get stuck in deadlocks, or take time to initialize. Kubernetes needs a way to detect these states to manage your Pods effectively. We use Health Probes to give the kubelet the instructions it needs to monitor your containers.

There are three primary types of probes:

  1. Liveness Probes: These check if your application is still running. If a liveness probe fails, Kubernetes assumes the application is deadlocked or broken and will kill the container and restart it to attempt a recovery.
  2. Readiness Probes: These check if your application is ready to accept traffic. If this probe fails, the Pod is removed from the service endpoints, meaning no traffic will be sent to it until it becomes "ready" again. This is crucial for apps that need to load large data into memory before serving users.
  3. Startup Probes: These are used for "slow-start" applications that might take a long time to initialize. If configured, the kubelet disables the other two probes until the startup probe succeeds, ensuring your app doesn't get killed prematurely by a liveness probe while it is still booting.

Here is how you define a simple HTTP liveness probe in your Pod specification:

spec:
  containers:
  - name: my-app
    image: my-app:latest
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 5

In this example, Kubernetes will wait 3 seconds after the container starts, then check the /healthz endpoint every 5 seconds. If the endpoint returns an error, the kubelet will restart the container. By combining these probes, you ensure your cluster automatically heals from crashes and prevents users from hitting applications that aren't yet ready to process requests.

Key Takeaway: Health probes allow Kubernetes to perform automated self-healing and traffic management by checking if your containers are running, initialized, and ready to serve.