How to Set Period and Timeout for Probe in Kubernetes
In Kubernetes, you set the probe's check interval using
periodSeconds and the response wait time using timeoutSeconds inside the probe configuration. These fields control how often Kubernetes runs the probe and how long it waits for a response before marking it as failed.Syntax
The periodSeconds field defines how often (in seconds) Kubernetes runs the probe. The timeoutSeconds field defines how long (in seconds) Kubernetes waits for the probe to respond before considering it failed.
Both fields are part of the livenessProbe, readinessProbe, or startupProbe sections in a Pod spec.
yaml
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
timeoutSeconds: 5Example
This example shows a Pod spec with a livenessProbe that checks the /healthz endpoint every 10 seconds and waits up to 5 seconds for a response before failing.
yaml
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: example-container
image: nginx
livenessProbe:
httpGet:
path: /healthz
port: 80
periodSeconds: 10
timeoutSeconds: 5Output
Pod 'example-pod' will have its liveness probe run every 10 seconds and wait up to 5 seconds for a response before marking the container as unhealthy.
Common Pitfalls
- Setting
timeoutSecondslonger thanperiodSecondscan cause overlapping probes and unexpected behavior. - Not setting these fields defaults to
periodSeconds: 10andtimeoutSeconds: 1, which might be too short or too long for your app. - For slow-starting apps, use
startupProbewith appropriate timeouts instead of onlylivenessProbe.
yaml
livenessProbe:
httpGet:
path: /healthz
port: 80
periodSeconds: 5
timeoutSeconds: 10 # Wrong: timeout longer than period
# Corrected:
livenessProbe:
httpGet:
path: /healthz
port: 80
periodSeconds: 10
timeoutSeconds: 5Quick Reference
| Field | Description | Default Value |
|---|---|---|
| periodSeconds | How often to run the probe (seconds) | 10 |
| timeoutSeconds | How long to wait for probe response (seconds) | 1 |
| initialDelaySeconds | Delay before starting probes (seconds) | 0 |
| failureThreshold | Number of failures before marking unhealthy | 3 |
Key Takeaways
Set
periodSeconds to control probe frequency and timeoutSeconds to control response wait time.Ensure
timeoutSeconds is less than or equal to periodSeconds to avoid overlapping probes.Use
startupProbe for slow-starting containers to avoid premature failure.Default values may not fit all apps; customize probes based on your app's behavior.
Probes help Kubernetes know when to restart or stop sending traffic to unhealthy containers.