Resolving Missing ps Command in Kubernetes Health Probes for Slim Docker Images
Issue
Kubernetes liveness and readiness probes failed in a Python 3.11 slim container due to the absence of the ps command. The probes relied on Unix utilities (ps aux | grep python) that were not included in the minimal python:3.11-slim Docker image, causing pods to be incorrectly marked as unhealthy and restarting continuously.
Culprit
The python:3.11-slim image excludes the procps package (which provides the ps command) to maintain a minimal footprint. This assumption mismatch—where probes relied on standard Unix utilities—caused failures when those utilities were unavailable in the container runtime.
Solution
Replaced the ps-dependent probe with a filesystem-based check that verifies the existence of the main container process (PID 1) by testing for /proc/1/status. This approach:
- Eliminates package dependencies: Works in any Linux container without requiring additional utilities.
- Maintains minimal overhead: Uses a simple filesystem check without spawning subprocesses.
- Ensures universal compatibility:
/proc/1/statusis present in all Linux containers with a running PID 1 process.
Outcome: The health probes now function correctly in slim container environments, ensuring stable pod operations while adhering to minimal image constraints.