Kubernetes
livenessProbe
pod management
container health
pod lifecycle

Kubernetes livenessProbe restarting vs destroying of the pod

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Kubernetes, the orchestration powerhouse for containerized applications, is renowned for its capabilities in managing container lifecycle through automatic scaling, deployment, and operations. Among its suite of features, the concept of `livenessProbe` plays a pivotal role in maintaining the health of applications. This article will delve into the technicalities of Kubernetes `livenessProbe`, specifically in relation to pod restarting versus destroying.

Understanding `livenessProbe`

`livenessProbe`, a Kubernetes feature, acts as a health check mechanism for containers running in pods. It determines the health of an application and influences Kubernetes to take corrective actions when an application fails to meet the expected states.

Why Do We Need `livenessProbe`?

Applications may encounter issues such as deadlocks, memory leaks, or crash loops. `livenessProbe` helps:

  • Detect deadlock situations.
  • Restart applications when they are dysfunctional.
  • Maintain high availability of services.

Types of Probes

Kubernetes offers three primary types of probes:

  1. HTTP GET Probe: Periodically sends an HTTP GET request to the container. If the response code indicates success (typically 2xx or 3xx), the container is assumed healthy.
  2. TCP Socket Probe: Tries to establish a TCP connection to a designated port on the container. If the connection succeeds, the container is considered healthy.
  3. Exec Probe: Executes a command inside the container. A zero exit status indicates success, otherwise, it's considered unhealthy.

Probe Configuration

A typical YAML configuration for a `livenessProbe` might appear as:

  • httpGet: Specifies the HTTP GET request configuration.
  • initialDelaySeconds: Time in seconds to delay before initiating the probe.
  • periodSeconds: Frequency (in seconds) of how often to perform the probe.
  • timeoutSeconds: Time in seconds after which the probe times out.
  • failureThreshold: Number of consecutive failures after which Kubernetes considers the container unhealthy.
  • Kubernetes attempts to restart the container within the same pod while retaining the pod identity.
  • Pod’s IP remains unchanged ensuring consistent network endpoints.
  • Any ephemeral storage in the container is lost unless persistent storage solutions are employed.
  • Kubernetes attempting to recreate the pod if specified by the `restartPolicy`.
  • Pod identity, along with its associated network configuration, may change.
  • Destruction is managed by higher-level control mechanisms like deployments or stateful sets to ensure application reliability.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.