An exec probe checks container health by running a command inside the container. Exit code zero means success; a non-zero exit code or timeout means failure. It suits applications that do not expose an HTTP health endpoint or accept TCP connections. section 6.2.2 section 6.2.5
A command-based liveness check
Configure the probe to run /usr/bin/healthcheck every two seconds. With timeoutSeconds set to 1 and failureThreshold set to 1, one command failure or timeout marks the container unhealthy and causes termination as configured. section 6.2.5
livenessProbe:
exec:
command: #1
- /usr/bin/healthcheck #1
periodSeconds: 2 #2
timeoutSeconds: 1 #3
failureThreshold: 1 #4
Use the manifest listing to see the exec command, polling interval, timeout, and failure threshold together. section 6.2.5
Design the command and its failure behavior carefully:
- Keep the command available on the container’s filesystem, because Kubernetes executes it inside the container. section 6.2.5
- Keep probe handlers lightweight; their CPU and memory use counts against the container and can reduce resources available to the application. section 6.2.7
- Avoid retry loops inside the command; use failureThreshold when several failed attempts should be required. section 6.2.7
- Do not confuse liveness with readiness: a failed readiness probe removes the pod from service endpoints rather than restarting it. section 11.6.1

