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?