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.
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:
- 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.
- 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.
- 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
/healthendpoint 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
- Liveness probe with http post
- Logs complaining extensions/v1beta1 Ingress is deprecated
- Logs in Kubernetes Pod not showing up
- Make RabbitMQ durable/persistent queues survive Kubernetes pod restart
- Locating data volumes in Docker Desktop Windows
- Logic to strategically place items in a container with minimum overlapping connections
- Manually change the status of a job to successful in kubernetes
- Many kubernetes secrets vs many keys in one k8s secret

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.