0
0
Kubernetesdevops~5 mins

Probe timing parameters (initialDelay, period, timeout) in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Kubernetes uses probes to check if your app is healthy and ready. Probe timing parameters control when and how often these checks happen, helping avoid false alarms and ensuring smooth app operation.
When your app needs some time to start before Kubernetes checks if it's ready
When you want Kubernetes to check your app's health regularly to restart it if it fails
When your app sometimes takes longer to respond and you want to avoid marking it unhealthy too soon
When you want to control how long Kubernetes waits for a probe response before considering it failed
Config File - pod.yaml
pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx:1.23
    livenessProbe:
      httpGet:
        path: /healthz
        port: 80
      initialDelaySeconds: 10
      periodSeconds: 5
      timeoutSeconds: 2
    readinessProbe:
      httpGet:
        path: /ready
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 3
      timeoutSeconds: 1

This pod configuration defines two probes: livenessProbe and readinessProbe.

  • initialDelaySeconds sets how many seconds Kubernetes waits before starting the first probe after the container starts.
  • periodSeconds sets how often Kubernetes runs the probe.
  • timeoutSeconds sets how long Kubernetes waits for the probe to respond before marking it failed.

These settings help Kubernetes know when your app is ready and healthy.

Commands
This command creates the pod with the defined probes and their timing parameters.
Terminal
kubectl apply -f pod.yaml
Expected OutputExpected
pod/example-pod created
This command checks the status of the pod to see if it is running and ready.
Terminal
kubectl get pods example-pod
Expected OutputExpected
NAME READY STATUS RESTARTS AGE example-pod 1/1 Running 0 10s
This command shows detailed information about the pod, including probe events and timing details.
Terminal
kubectl describe pod example-pod
Expected OutputExpected
Name: example-pod Namespace: default Containers: example-container: Container ID: docker://abcdef123456 Image: nginx:1.23 State: Running Ready: True Restart Count: 0 Liveness: http-get http://:80/healthz delay=10s timeout=2s period=5s Readiness: http-get http://:80/ready delay=5s timeout=1s period=3s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 1m default-scheduler Successfully assigned default/example-pod to node-1 Normal Pulled 1m kubelet Container image "nginx:1.23" already present on machine Normal Created 1m kubelet Created container example-container Normal Started 1m kubelet Started container example-container
Key Concept

If you remember nothing else from this pattern, remember: initialDelaySeconds waits before first check, periodSeconds sets check frequency, and timeoutSeconds sets how long to wait for a response.

Common Mistakes
Setting initialDelaySeconds too low so probes start before the app is ready
Kubernetes may mark the app as unhealthy and restart it unnecessarily.
Set initialDelaySeconds to a value that matches your app's startup time.
Setting timeoutSeconds too low causing probes to fail if the app responds slowly
Probes fail even if the app is healthy but slow, causing restarts.
Set timeoutSeconds to a reasonable value that allows your app to respond.
Setting periodSeconds too high, so failures are detected too late
Kubernetes takes longer to detect and fix unhealthy apps.
Set periodSeconds to a balanced value for timely health checks without overload.
Summary
Define probe timing parameters in pod.yaml to control health and readiness checks.
Use kubectl apply to create the pod and kubectl get/describe to verify probe behavior.
Adjust initialDelaySeconds, periodSeconds, and timeoutSeconds to match your app's needs.