📖 Scenario: You are managing a Kubernetes deployment for a simple web application. To keep your application healthy, you need to configure readiness and liveness probes with proper timing settings.These probes help Kubernetes know when your app is ready to serve traffic and when it needs to be restarted.
🎯 Goal: Learn how to set the initialDelaySeconds, periodSeconds, and timeoutSeconds parameters in Kubernetes probes to control when and how often Kubernetes checks your app's health.
📋 What You'll Learn
Create a Kubernetes pod spec with a container named webapp
Add a readiness probe with initialDelaySeconds, periodSeconds, and timeoutSeconds
Add a liveness probe with the same timing parameters
Print the final pod YAML to verify the probe settings
💡 Why This Matters
🌍 Real World
Kubernetes probes help keep applications running smoothly by checking their health and readiness before sending traffic or restarting them.
💼 Career
Understanding probe timing parameters is essential for DevOps engineers and site reliability engineers to maintain stable and resilient Kubernetes deployments.
Progress0 / 4 steps
1
Create the basic pod YAML with a container
Create a Kubernetes pod YAML named pod.yaml with a single container named webapp using the image nginx:latest. Include the apiVersion, kind, metadata, and spec sections with the container defined.
Kubernetes
Hint
Start with the basic pod structure and add the container details exactly as shown.
2
Add readiness probe timing parameters
Add a readinessProbe to the webapp container with initialDelaySeconds: 5, periodSeconds: 10, and timeoutSeconds: 2. Use an httpGet action on path / and port 80.
Kubernetes
Hint
Indent the readinessProbe correctly under the container and include all timing parameters.
3
Add liveness probe timing parameters
Add a livenessProbe to the webapp container with initialDelaySeconds: 15, periodSeconds: 20, and timeoutSeconds: 3. Use an httpGet action on path /healthz and port 80.
Kubernetes
Hint
Place the livenessProbe at the same indentation level as readinessProbe under the container.
4
Print the final pod YAML
Print the contents of pod.yaml to verify the readiness and liveness probe timing parameters are set correctly.
Kubernetes
Hint
Use a command or code to print the full YAML content to check your work.
Practice
(1/5)
1. What does the initialDelaySeconds parameter control in a Kubernetes probe?
easy
A. The time to wait before the first probe check starts
B. The maximum time to wait for a probe response
C. The frequency of probe checks after the first one
D. The number of retries before marking the pod as failed
Solution
Step 1: Understand the role of initialDelaySeconds
This parameter sets how long Kubernetes waits before performing the first probe check on a container.
Step 2: Differentiate from other timing parameters
timeoutSeconds limits wait time per check, and periodSeconds sets how often checks repeat after the first.
Final Answer:
The time to wait before the first probe check starts -> Option A
Quick Check:
initialDelaySeconds = wait before first check [OK]
Hint: initialDelaySeconds delays first check only [OK]
Common Mistakes:
Confusing initialDelaySeconds with timeoutSeconds
Thinking it controls check frequency
Assuming it sets retry count
2. Which of the following is the correct syntax to set a liveness probe with initialDelaySeconds of 10, periodSeconds of 5, and timeoutSeconds of 2 in a pod spec?
easy
A. livenessProbe:
initialDelaySeconds: '10'
periodSeconds: '5'
timeoutSeconds: '2'
B. livenessProbe:
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 2
C. livenessProbe:
initialDelay: 10
period: 5
timeout: 2
D. livenessProbe:
delayInitialSeconds: 10
periodSeconds: 5
timeoutSeconds: 2
Solution
Step 1: Check correct parameter names
The correct keys are initialDelaySeconds, periodSeconds, and timeoutSeconds exactly as spelled.
Step 2: Validate value types and syntax
Values should be integers without quotes. livenessProbe:
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 2 uses correct keys and integer values.
Final Answer:
Correct YAML with proper keys and integer values -> Option B
Quick Check:
Use exact keys and integer values [OK]
Hint: Use exact parameter names with integer values [OK]
If the container starts at time 0, when will the first probe timeout occur if the probe command does not respond?
medium
A. At 15 seconds
B. At 5 seconds
C. At 10 seconds
D. At 8 seconds
Solution
Step 1: Calculate when first probe starts
The first probe starts after initialDelaySeconds, so at 5 seconds.
Step 2: Add timeoutSeconds to find timeout moment
The probe waits up to timeoutSeconds (3 seconds) for a response, so timeout occurs at 5 + 3 = 8 seconds.
Final Answer:
At 8 seconds -> Option D
Quick Check:
initialDelay + timeout = 8 seconds [OK]
Hint: Add initialDelaySeconds and timeoutSeconds for first timeout [OK]
Common Mistakes:
Using periodSeconds instead of timeoutSeconds for timeout
Forgetting to add initialDelaySeconds
Assuming timeout happens at periodSeconds
4. You configured a readiness probe with initialDelaySeconds: 0, periodSeconds: 2, and timeoutSeconds: 5. The probe command hangs and never returns. What is the likely problem?
medium
A. initialDelaySeconds cannot be zero
B. periodSeconds must be greater than timeoutSeconds
C. timeoutSeconds is longer than periodSeconds, causing overlapping probes
D. timeoutSeconds must be less than 1 second
Solution
Step 1: Analyze timing relationship
The probe runs every 2 seconds (periodSeconds) but waits up to 5 seconds (timeoutSeconds) for a response.
Step 2: Identify overlapping probes issue
Since timeout is longer than period, new probes start before previous finish, causing overlap and possible resource issues.
Final Answer:
timeoutSeconds is longer than periodSeconds, causing overlapping probes -> Option C
Hint: timeoutSeconds should be less than or equal to periodSeconds [OK]
Common Mistakes:
Thinking initialDelaySeconds cannot be zero
Assuming timeoutSeconds must be less than 1
Ignoring probe overlap effects
5. You want a startup probe to check a container's readiness only after 30 seconds, then check every 10 seconds, with each check timing out after 4 seconds. Which configuration correctly sets these parameters?
hard
A. startupProbe:
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 4
B. startupProbe:
initialDelaySeconds: 10
periodSeconds: 30
timeoutSeconds: 4
C. startupProbe:
initialDelaySeconds: 30
periodSeconds: 4
timeoutSeconds: 10
D. startupProbe:
initialDelaySeconds: 4
periodSeconds: 10
timeoutSeconds: 30
Solution
Step 1: Match each parameter to requirement
initialDelaySeconds should be 30 to delay first check, periodSeconds 10 for check frequency, and timeoutSeconds 4 for max wait per check.