0
0
Kubernetesdevops~10 mins

Exec probe configuration in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Exec probe configuration
Pod starts
Kubelet runs exec probe
Exec command runs inside container
Command exits with code
Exit code 0?
YesProbe success
Exit code != 0?
YesProbe failure
Kubelet acts on probe result
The kubelet runs a command inside the container. If the command exits with 0, the probe is successful; otherwise, it fails.
Execution Sample
Kubernetes
livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5
This probe runs 'cat /tmp/healthy' inside the container every 5 seconds after an initial delay of 5 seconds to check if the container is healthy.
Process Table
StepActionCommand RunExit CodeProbe ResultKubelet Response
1Pod startsPod running, probe scheduled
2Wait initialDelaySecondsWaiting 5 seconds before first probe
3Run exec probecat /tmp/healthy0SuccessNo action needed
4Wait periodSecondsWait 5 seconds before next probe
5Run exec probecat /tmp/healthy1FailureRestart container
6Container restartsPod restarting container
7Run exec probecat /tmp/healthy0SuccessNo action needed
💡 Probe runs repeatedly every periodSeconds; failure triggers container restart.
Status Tracker
VariableStartAfter Step 3After Step 5After Step 7
Exit CodeN/A010
Probe ResultN/ASuccessFailureSuccess
Container StateStartingRunningRestartingRunning
Key Moments - 3 Insights
Why does the probe fail when the command exits with code 1?
Because in the execution_table at Step 5, the exit code is 1, which means the command did not succeed, so the probe result is Failure, triggering a container restart.
What happens during initialDelaySeconds before the first probe?
As shown in Step 2, the kubelet waits the initialDelaySeconds (5 seconds) before running the first exec probe to give the container time to start.
Does the exec probe run only once?
No, as seen in Steps 3, 5, and 7, the exec probe runs repeatedly every periodSeconds (5 seconds) to continuously check container health.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 3. What is the exit code of the exec command?
A0
B1
CSuccess
DFailure
💡 Hint
Check the 'Exit Code' column at Step 3 in the execution_table.
At which step does the kubelet decide to restart the container?
AStep 3
BStep 5
CStep 7
DStep 2
💡 Hint
Look at the 'Kubelet Response' column to find when the container restarts.
If the exec command always exits with 0, how would the container state change over time?
AContainer keeps restarting
BContainer stays running without restarts
CContainer stops after first probe
DContainer never starts
💡 Hint
Refer to the 'Container State' in variable_tracker when Exit Code is 0.
Concept Snapshot
Exec probe runs a command inside the container.
If command exits 0, probe succeeds; else fails.
Configured under livenessProbe or readinessProbe.
initialDelaySeconds waits before first run.
periodSeconds sets how often to run.
Failure can restart container.
Full Transcript
Exec probe configuration in Kubernetes means the kubelet runs a command inside the container to check health. The command's exit code determines success (0) or failure (non-zero). The probe runs after an initial delay and repeats periodically. If the probe fails, kubelet can restart the container. This visual trace shows the pod starting, waiting initialDelaySeconds, running the exec command, and reacting based on the exit code. Variables like exit code, probe result, and container state change step by step. Key moments clarify why exit code matters, the role of initial delay, and repeated probe runs. Quiz questions test understanding of exit codes, restart timing, and container state behavior.