Exec Command Probes
What you'll learn: How to use custom shell commands inside your containers to determine their health status.
What Are Exec Command Probes?
An exec probe runs a command directly inside your container and checks the exit code. If the command returns 0, Kubernetes considers the probe successful. Any non-zero exit code signals failure. This gives you complete control to define health checks using custom scripts, database queries, file checks, or any executable available in your container.
Think of it like a doctor asking you to perform a specific task—"Touch your toes"—to verify you're healthy, rather than just checking your temperature or pulse.
How Exec Probes Work
When Kubernetes runs an exec probe, it executes the specified command in the container's main process namespace. The command has access to the container's filesystem, environment variables, and installed tools.
Basic Configuration
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 10
This probe checks if a file exists. If cat successfully reads /tmp/healthy, it returns exit code 0 (success). If the file is missing, cat fails with a non-zero code.
Custom Script Example
readinessProbe:
exec:
command:
- /bin/sh
- -c
- "pg_isready -U postgres && test -f /var/run/migrations-complete"
initialDelaySeconds: 10
periodSeconds: 5
This checks both that PostgreSQL is accepting connections AND that a migration marker file exists—custom logic you define.
When to Use Exec Probes
Use exec probes when HTTP endpoints or TCP sockets don't capture your health requirements. Perfect for checking file states, database connectivity, or running validation scripts.
Key Takeaway: Exec probes let you define container health using any command or script, giving you maximum flexibility when standard HTTP/TCP checks aren't sufficient.