Kubernetes
Pods
Probes
Health Checks
Container Monitoring

Kubernetes Probes - What is the order in which they examine the pod?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Kubernetes probes are essential components in ensuring the reliability and availability of applications running in containers. They continuously monitor the health of pods and influence decisions regarding their lifecycle based on pre-defined criteria.

Understanding Kubernetes Probes

Kubernetes defines three types of probes to examine the health of containers:

  1. Liveness Probe: This determines if the container is running. If the liveness probe fails, Kubernetes will kill the container and potentially restart it based on the pod's restart policy.
  2. Readiness Probe: This checks if the container is ready to handle requests. If the readiness probe fails, the endpoint is removed from Kubernetes Service, ensuring it does not receive traffic.
  3. Startup Probe: This is used when starting the application takes a significant amount of time. It prevents the killing of the pod due to failed liveness probes before the application is fully rolled out.

Sequence of Probe Execution

The order of execution for these probes is crucial in understanding how Kubernetes ensures application availability:

  1. Startup Probe (if defined): This runs first when a container starts. If the startup probe fails beyond a certain threshold, the pod is killed. If the startup probe succeeds, Kubernetes moves on to the liveness and readiness probes.
  2. Liveness Probe: Once the startup probe passes successfully, Kubernetes uses the liveness probe to continuously check if the container is alive.
  3. Readiness Probe: Simultaneously with the liveness probe, the readiness probe ensures the container can handle requests by checking application-specific endpoints.

Probe Configurations and Examples

Kubernetes allows defining probes via several mechanisms including HTTP requests, TCP socket checks, and command executions.

HTTP-Based Probe

Here's an example of how you can configure HTTP-based liveness and readiness probes:

  • name: example-container
  • `initialDelaySeconds`: Time in seconds before starting the probe after the container is started.
  • `periodSeconds`: Frequency of performing the probe.
  • `timeoutSeconds`: Time to wait for a probe to succeed.
  • `successThreshold`: Number of consecutive successes for the probe to be considered successful after having failed.
  • `failureThreshold`: Number of consecutive failures for the probe to be considered failed.
  • Pod Lifecycle Impacts: Probes can significantly influence the pod lifecycle, affecting the scalability and reliability of applications.
  • Graceful Shutdowns: Using readiness probes can facilitate graceful shutdowns by temporarily removing the pod from service traffic before it is terminated.
  • Failure Thresholds: Setting appropriate thresholds for failure and success is crucial to ensure that transient glitches do not result in full restarts.

Course illustration
Course illustration