Startup probe concept in Kubernetes - Time & Space Complexity
We want to understand how the startup probe affects the time it takes for a container to become ready.
How does the number of probe checks grow as the container startup time changes?
Analyze the time complexity of this startup probe configuration.
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: example-container
image: example-image
startupProbe:
exec:
command:
- cat
- /tmp/healthy
failureThreshold: 5
periodSeconds: 10
This code sets a startup probe that runs a command every 10 seconds, up to 5 failures allowed before restart.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The startup probe command execution every periodSeconds.
- How many times: Up to failureThreshold times if the probe keeps failing.
The number of probe checks grows linearly with the failureThreshold setting.
| Input Size (failureThreshold) | Approx. Operations (probe runs) |
|---|---|
| 3 | 3 probe checks |
| 5 | 5 probe checks |
| 10 | 10 probe checks |
Pattern observation: More allowed failures mean more probe executions before restart.
Time Complexity: O(n)
This means the number of probe executions grows directly with the failureThreshold value.
[X] Wrong: "The startup probe runs only once regardless of failureThreshold."
[OK] Correct: The probe runs repeatedly until it succeeds or reaches failureThreshold, so the number of runs depends on failureThreshold.
Understanding how probes work and their timing helps you explain container readiness and failure handling clearly in real projects.
"What if we change periodSeconds to a smaller value? How would the time complexity of probe executions change?"
Practice
startupProbe in Kubernetes?Solution
Step 1: Understand the role of startupProbe
The startupProbe is designed to check if an application has started successfully before Kubernetes runs readiness or liveness probes.Step 2: Differentiate from other probes
Unlike liveness or readiness probes, startupProbe prevents Kubernetes from killing pods that take longer to start.Final Answer:
To check if the application has started before other health checks run -> Option CQuick Check:
startupProbe checks app start status = A [OK]
- Confusing startupProbe with livenessProbe
- Thinking startupProbe manages resource usage
- Assuming startupProbe handles traffic routing
startupProbe using an HTTP GET request in a pod spec?Solution
Step 1: Identify correct HTTP GET syntax for startupProbe
The startupProbe useshttpGetwithpathandportfields, plus timing settings likefailureThresholdandperiodSeconds.Step 2: Compare options for correctness
startupProbe: httpGet: path: /healthz port: 8080 failureThreshold: 30 periodSeconds: 10 correctly useshttpGetwith path /healthz, port 8080, and timing fields. Other options use exec or tcpSocket or wrong ports/fields.Final Answer:
startupProbe: httpGet: path: /healthz port: 8080 failureThreshold: 30 periodSeconds: 10 -> Option BQuick Check:
startupProbe HTTP GET with path and port = A [OK]
- Using exec probe syntax instead of httpGet
- Missing failureThreshold or periodSeconds
- Incorrect port or path values
startupProbe:
httpGet:
path: /start
port: 8080
failureThreshold: 5
periodSeconds: 2
livenessProbe:
httpGet:
path: /live
port: 8080
initialDelaySeconds: 10
periodSeconds: 5Solution
Step 1: Calculate startupProbe failure timeout
failureThreshold 5 and periodSeconds 2 means Kubernetes waits 5*2=10 seconds of failed startupProbe checks before restarting.Step 2: Understand probe precedence during startup
During startup, startupProbe controls pod health. LivenessProbe starts after startupProbe succeeds, so restart depends on startupProbe failures first.Final Answer:
Kubernetes will restart the pod after 10 seconds of startupProbe failures -> Option DQuick Check:
startupProbe failureThreshold * periodSeconds = restart delay [OK]
- Confusing startupProbe failure timing with livenessProbe
- Assuming readinessProbe triggers restart
- Ignoring startupProbe during pod startup
Solution
Step 1: Identify cause of immediate restarts
If the startupProbe fails too quickly, Kubernetes restarts the pod before it finishes starting.Step 2: Adjust startupProbe timing
Increasing failureThreshold and periodSeconds gives the app more time to start before Kubernetes kills it.Final Answer:
Increase failureThreshold and periodSeconds to allow more startup time -> Option AQuick Check:
Longer startupProbe timeout prevents premature restarts [OK]
- Removing startupProbe loses slow start protection
- Confusing startupProbe with readinessProbe
- Setting initialDelaySeconds on livenessProbe doesn't fix startup timing
Solution
Step 1: Calculate total startupProbe timeout needed
App needs 3 minutes (180 seconds) to start. Total timeout = failureThreshold x periodSeconds.Step 2: Choose values matching 180 seconds
SetfailureThresholdto 18 andperiodSecondsto 10: 18 x 10 = 180 seconds, allowing full startup time before restart.Step 3: Evaluate other options
SetfailureThresholdto 1 andperiodSecondsto 100:failureThresholdto 1 andperiodSecondsto 100 = 100 seconds (too short). SetfailureThresholdto 3 andperiodSecondsto 30: 3 x 30 = 90 seconds (too short). Disable startupProbe and rely on livenessProbe withinitialDelaySeconds180 disables startupProbe, risking premature restarts from livenessProbe.Final Answer:
Set failureThreshold to 18 and periodSeconds to 10 -> Option AQuick Check:
failureThreshold x periodSeconds = startup timeout [OK]
- Configuring insufficient total timeout (failureThreshold x periodSeconds < 180s)
- Disabling startupProbe causing premature restarts
- Setting only initialDelaySeconds without startupProbe
Ready to prove it?
Pass the test and this pattern moves unknown
