Exec probe configuration in Kubernetes - Time & Space Complexity
We want to understand how the time it takes to run an exec probe changes as the commands or containers grow.
Specifically, how does the exec probe's execution time grow with the complexity of the command it runs?
Analyze the time complexity of the following exec probe configuration in Kubernetes.
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 10
This probe runs the command cat /tmp/healthy inside the container to check if the app is ready.
Look at what repeats when the exec probe runs.
- Primary operation: Running the exec command inside the container.
- How many times: The probe runs repeatedly every
periodSeconds(e.g., every 10 seconds).
The time to run the exec probe depends mostly on the command's complexity and the file size it reads.
| Input Size (file size or command complexity) | Approx. Operations |
|---|---|
| Small file (10 bytes) | Very few operations, quick execution |
| Medium file (1 KB) | More operations, takes longer but still fast |
| Large file (1 MB) | Many operations, execution time grows roughly with file size |
Pattern observation: Execution time grows roughly in proportion to the command's workload, like reading a bigger file takes longer.
Time Complexity: O(n)
This means the exec probe's run time grows linearly with the size of the data or complexity of the command it executes.
[X] Wrong: "The exec probe always runs in constant time regardless of the command or file size."
[OK] Correct: The exec probe runs a command inside the container, so if the command processes more data or does more work, it takes longer.
Understanding how exec probes scale with command complexity helps you design efficient health checks that don't slow down your app.
What if we changed the exec command to run a script that loops over 1000 files? How would the time complexity change?
Practice
exec probe in Kubernetes?Solution
Step 1: Understand exec probe functionality
An exec probe runs a command inside the container to check its health status.Step 2: Compare with other options
Options A, B, and D relate to scheduling, networking, and storage, not health checks.Final Answer:
To run a command inside a container to check if it is healthy -> Option DQuick Check:
Exec probe = runs command inside container [OK]
- Confusing exec probe with port exposure
- Thinking exec probe schedules pods
- Mixing exec probe with storage management
Solution
Step 1: Check exec command format
The command must be an array of strings, e.g., ['cat', '/tmp/healthy'].Step 2: Validate YAML structure
livenessProbe:\n exec:\n command: ['cat', '/tmp/healthy']\n initialDelaySeconds: 5\n periodSeconds: 10 correctly uses the array syntax and includes initialDelaySeconds and periodSeconds.Final Answer:
Correct exec probe with command array and delays -> Option AQuick Check:
Exec command = array of strings [OK]
- Using a single string instead of array for command
- Confusing exec probe with httpGet probe
- Omitting required indentation or keys
livenessProbe:
exec:
command: ['test', '-f', '/tmp/healthy']
initialDelaySeconds: 3
periodSeconds: 5
What happens if the file /tmp/healthy does not exist inside the container?Solution
Step 1: Understand exec probe command
The command 'test -f /tmp/healthy' returns success if the file exists, failure if not.Step 2: Effect of probe failure
If the probe fails repeatedly, Kubernetes restarts the container to recover.Final Answer:
The probe fails and Kubernetes restarts the container after retries -> Option CQuick Check:
Missing file = probe fails = restart [OK]
- Assuming probe passes if file missing
- Thinking container deletes without restart
- Believing probe ignores errors silently
Solution
Step 1: Check exec command syntax
Exec probe commands must be an array of strings; a single string causes probe failure.Step 2: Understand probe failure effect
If the probe fails, the pod is not marked ready, so it never becomes ready.Final Answer:
Exec command missing array syntax causes probe failure -> Option AQuick Check:
Exec command array syntax missing = probe fails [OK]
- Ignoring command array syntax errors
- Blaming initialDelaySeconds without checking command
- Confusing readiness with resource limits
['/bin/check.sh'], retries every 5 seconds, and fails after 3 unsuccessful attempts. Which is the correct YAML snippet?Solution
Step 1: Verify command syntax and initial delay
Command must be an array; initialDelaySeconds must be 10 as required.Step 2: Check periodSeconds and failureThreshold
PeriodSeconds should be 5 for retry every 5 seconds; failureThreshold 3 means fail after 3 tries.Final Answer:
Correct YAML with command array, initialDelaySeconds 10, periodSeconds 5, failureThreshold 3 -> Option BQuick Check:
Command array + delays + failureThreshold correct = livenessProbe:\n exec:\n command: ['/bin/check.sh']\n initialDelaySeconds: 10\n periodSeconds: 5\n failureThreshold: 3 [OK]
- Using string instead of array for command
- Swapping periodSeconds and initialDelaySeconds values
- Setting failureThreshold too low or missing
Ready to prove it?
Pass the test and this pattern moves unknown
