Kubernetes
Liveness Probe
Pods
Container Orchestration
Health Check

Liveness-Probe of one pod via another

System Design practice on Codemia

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

Practice system design

Introduction

In the world of Kubernetes, ensuring that pods are running as expected is crucial for maintaining the reliability and performance of applications. One critical aspect of this is determining the liveness of a pod, which can signal issues that may require the pod to be restarted. A liveness probe helps achieve this by periodically checking the health of a container. This article delves into performing a liveness probe of one pod via another, leveraging Kubernetes features to enhance monitoring and resilience.

Understanding Liveness Probes

A liveness probe determines whether a container in a pod is still running. If the liveness probe fails, the kubelet considers the container to be unhealthy and will attempt to kill and restart it. This ensures that problems are quickly resolved, minimizing downtime.

Key Methods for Implementing Liveness Probes

Kubernetes provides several methods for implementing liveness probes:

  1. HTTP GET Requests: The kubelet sends an HTTP request to the container. If the server returns a status code greater than or equal to 200 and less than 400, the container is considered healthy.
  2. TCP Socket: The kubelet attempts to establish a TCP connection to the container on a specified port. If it can establish a connection, the container is considered healthy.
  3. Command Execution: The kubelet runs a specified command inside the container. If the command succeeds (returns a 0 status), the container is considered healthy.

Implementing Liveness Probes via Another Pod

Sometimes, one pod may need to monitor the health of another. This strategy can be particularly useful for microservices architectures, where different services need to ensure upstream dependencies are available before executing certain tasks.

Example Implementation

In this scenario, we have two pods; Pod-A and Pod-B, where Pod-B performs the liveness check on Pod-A.

  • name: myapp-container
    • containerPort: 80
  • name: probe-container
    • /bin/sh
    • -c
    • |
  • Pod-A: It contains a simple web application with a /health endpoint that returns a 200 status code when healthy.
  • Pod-B: It continuously queries Pod-A's health endpoint. If the endpoint does not return a successful HTTP status code, Pod-B's process will exit with status 1, indicating an issue.
  • Service Discovery: Ensure that Pod-B can resolve Pod-A by using Kubernetes service names or DNS resolution.
  • Network Policies: Validate that network policies allow Pod-B to communicate with Pod-A.
  • Security Implications: Implement proper authentication and authorization mechanisms to prevent unauthorized access between pods.

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.