What Is a Readiness Probe in Kubernetes? Definition & Deep Dive

Readiness Probe in Kubernetes

A Readiness Probe is a key mechanism in Kubernetes used to determine whether an application running in a container is ready to start serving traffic. Even if a container is healthy at the operating-system level, its application might still be loading configuration files, warming up caches, or waiting for dependent services to become available. During this “startup” or “initialization” phase, sending requests to the application could result in errors. Readiness probes solve this problem by telling the Kubernetes scheduler not to route traffic to a pod until it signals it is ready.

How Readiness Probes Work

Kubernetes provides several types of probes— liveness, readiness, and startup—each serving a distinct purpose. A readiness probe specifically controls the pod’s availability in a Kubernetes Service load-balancing pool:

  1. Probe Mechanism: The probe is a periodic check. Kubernetes sends a request (e.g., an HTTP GET or a TCP check) to the container at a specified endpoint. If the check passes (e.g., an HTTP 200 response), Kubernetes interprets this as the application being “ready” to serve traffic.
  2. Pod Readiness Gate: When a container’s readiness probe indicates success, Kubernetes sets the pod’s status to Ready: true. Only pods marked as Ready are included in service endpoints. If the readiness probe fails at any point, Kubernetes removes that pod from the pool, ensuring that no traffic is routed to a potentially malfunctioning or uninitialized container.
  3. Configuration Parameters: You can configure several parameters, such as initialDelaySeconds (how long to wait before starting the probe), periodSeconds (interval between each probe), timeoutSeconds (how long to wait for a probe response), and more. These parameters allow you to fine-tune the readiness check to accommodate varying startup times and resource constraints.

When to Use a Readiness Probe

What Happens When a Readiness Probe Fails?

If a readiness probe fails—for instance, if the container’s health endpoint returns an error or times out—Kubernetes immediately marks the pod as “unready.” The pod is then removed from the pool of available endpoints in the corresponding service. Traffic will not be sent to the pod until the readiness probe starts succeeding again. This mechanism prevents users from experiencing errors caused by partially initialized or malfunctioning containers.

Comparing Startup and Readiness Probes

In short, use a startup probe to handle lengthy or complex initialization procedures, and use a readiness probe to manage ongoing availability for incoming traffic.

Example Readiness Probe Configuration

Below is a simplified snippet in a pod specification:

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: my-app-container
    image: my-app:latest
    readinessProbe:
      httpGet:
        path: /health
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 10

In this example, Kubernetes will wait 5 seconds before performing the first check (initialDelaySeconds). Every 10 seconds (periodSeconds), it sends an HTTP GET request to /health on port 8080. If the response indicates success (e.g., HTTP 200), the container is deemed ready.

Value proposition

Issues to look out for

How Do You Fix a Readiness Probe?

  1. Verify the Probe Endpoint: Make sure the path (e.g., /health) and port number match what your application actually supports. If your health endpoint is /healthz, don’t forget to reflect that in your readiness probe configuration.
  2. Adjust Timing Parameters: If your application needs more time to start up or respond, increase initialDelaySeconds, timeoutSeconds, or periodSeconds. This ensures Kubernetes gives your container sufficient time to become ready.
  3. Check Application Logs: Look at container logs to see if the application is throwing errors or still initializing. Often, logs can reveal issues such as dependency failures or misconfiguration that lead to failing readiness checks.
  4. Separate Heavy Initialization: If your container does a lot of work at startup, consider moving this logic to a pre-start script, or use a startup probe to give the container a chance to properly initialize before readiness probes kick in.