0
0
KubernetesHow-ToBeginner · 3 min read

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: 5
💻

Example

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: 5
Output
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 timeoutSeconds longer than periodSeconds can cause overlapping probes and unexpected behavior.
  • Not setting these fields defaults to periodSeconds: 10 and timeoutSeconds: 1, which might be too short or too long for your app.
  • For slow-starting apps, use startupProbe with appropriate timeouts instead of only livenessProbe.
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: 5
📊

Quick Reference

FieldDescriptionDefault Value
periodSecondsHow often to run the probe (seconds)10
timeoutSecondsHow long to wait for probe response (seconds)1
initialDelaySecondsDelay before starting probes (seconds)0
failureThresholdNumber of failures before marking unhealthy3

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.