Sub topic 4
Timing and threshold parameters and their defaults
This chapter assumes you can read Deployment manifests, know that the kubelet runs probes on each node, and know the four probe mechanisms (httpGet, tcpSocket, exec, gRPC). Here you learn the six fields that control when and how often a probe runs, and how to turn them into a time budget.
The six fields
Every probe, whatever its mechanism, accepts the same timing fields.
| Field | Default | Minimum | Meaning |
|---|---|---|---|
| `initialDelaySeconds` | 0 | 0 | Seconds to wait after the container starts before the first probe. |
| `periodSeconds` | 10 | 1 | Seconds between probes. |
| `timeoutSeconds` | 1 | 1 | Seconds to wait for a result before counting the attempt as failed. |
| `successThreshold` | 1 | 1 | Consecutive successes needed to count as healthy again after a failure. |
| `failureThreshold` | 3 | 1 | Consecutive failures needed to act. |
| `terminationGracePeriodSeconds` | Pod value | 1 | Optional per-probe override of the grace period used when a liveness or startup probe kills the container. |
Two rules apply to the thresholds. successThreshold must be 1 for liveness and startup probes. Only readiness probes can require more than one success.
What "act" means
The probe type decides what happens when failureThreshold is reached.
- A failing readiness probe marks the Pod not ready, and the Pod is removed from Service endpoints. The container keeps running.
- A failing liveness probe makes the kubelet kill the container and apply the restart policy.
- A failing startup probe is treated like a liveness failure: the container is killed and restarted.
A timeout counts as a failure. A probe that hangs for longer than timeoutSeconds is the same as one that returned an error.
Turning fields into a time budget
A failing container is detected after roughly failureThreshold × periodSeconds seconds. Add up to one extra timeoutSeconds for a hung final attempt.
Take the liveness probe from the earlier Deployment: periodSeconds: 10, timeoutSeconds: 2, failureThreshold: 3. A container that hangs just after a successful probe is restarted after about 30 seconds, plus up to 2 seconds for the last timeout. The readiness probe uses periodSeconds: 5 and failureThreshold: 3, so traffic stops after about 15 seconds.
The startup probe in that manifest uses periodSeconds: 5 and failureThreshold: 30. That allows 150 seconds for startup. Liveness and readiness probes do not begin until the startup probe succeeds.
startupProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 5
failureThreshold: 30
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3Choosing values
- Start from the application's real behavior. Measure the slowest normal startup and the slowest normal response of the health endpoint.
- Set
timeoutSecondsabove normal latency. The default of 1 second is often too tight for an endpoint that touches a cache or runs under CPU limits. - Prefer a startup probe over a large
initialDelaySeconds. A fixed delay wastes time on fast starts and still fails on slow ones. A startup probe begins checking early and gives up only after its full budget. - Keep liveness slower than readiness. Restarts are costly, so liveness should tolerate more failures or longer periods than readiness.
- Use
successThresholdabove 1 only for readiness. It stops a flapping Pod from rejoining the Service after one lucky success.
Exercise
A container has a liveness probe with periodSeconds: 5, timeoutSeconds: 3, and failureThreshold: 4. The container deadlocks right after a successful probe, and every later probe times out. Roughly how long until the kubelet kills it, and which fields did you use?
Show answer
About 20 seconds plus up to 3 seconds for the last timeout (failureThreshold × periodSeconds = 4 × 5, plus timeoutSeconds). A timeout counts as a failure, so four consecutive timed-out probes trigger the restart.
Exercise
Why can you not set successThreshold: 2 on a liveness probe, and what is a reasonable use of it on a readiness probe?
Show answer
Liveness and startup probes require successThreshold to be 1, because a container that passes should simply keep running. On a readiness probe, a value of 2 or more makes a Pod prove it is stable before it receives traffic again after a failure.