📖 Scenario: You are deploying a web application in Kubernetes. You want to make sure the application only receives traffic when it is ready to serve users. Kubernetes uses a readiness probe to check if the app is ready.
🎯 Goal: Learn how to add a readiness probe to a Kubernetes pod configuration to check the app's readiness using an HTTP GET request.
📋 What You'll Learn
Create a pod manifest with a container named webapp
Add a readiness probe that uses an HTTP GET request on path /ready and port 8080
Set initial delay seconds to 5 and period seconds to 10
Print the pod manifest YAML to verify the readiness probe is configured
💡 Why This Matters
🌍 Real World
Readiness probes help Kubernetes know when your app is ready to receive traffic, avoiding errors and improving user experience.
💼 Career
Understanding readiness probes is essential for DevOps roles managing Kubernetes deployments to ensure reliable and stable applications.
Progress0 / 4 steps
1
Create the basic pod manifest
Create a Kubernetes pod manifest named pod.yaml with a pod named webapp-pod and a container named webapp using the image nginx.
Kubernetes
Hint
Use apiVersion: v1, kind: Pod, and specify metadata.name and spec.containers.
2
Add readiness probe configuration
Add a readinessProbe to the webapp container that uses an HTTP GET request on path /ready and port 8080.
Kubernetes
Hint
Indent readinessProbe under the container and use httpGet with path and port.
3
Set initial delay and period seconds for readiness probe
Add initialDelaySeconds: 5 and periodSeconds: 10 to the readinessProbe configuration.
Kubernetes
Hint
Place initialDelaySeconds and periodSeconds at the same level as httpGet inside readinessProbe.
4
Print the pod manifest
Print the complete pod manifest YAML to verify the readiness probe is configured correctly.
Kubernetes
Hint
Use a print statement to show the manifest is ready.
Practice
(1/5)
1. What is the main purpose of a readiness probe in Kubernetes?
easy
A. To tell Kubernetes when a container is ready to receive traffic
B. To restart a container if it crashes
C. To monitor the CPU usage of a container
D. To update the container image automatically
Solution
Step 1: Understand readiness probe role
A readiness probe checks if a container is ready to accept requests, preventing traffic to unready containers.
Step 2: Compare with other options
Other options describe different Kubernetes features: restarts (liveness probe), monitoring (metrics), and updates (deployments).
Final Answer:
To tell Kubernetes when a container is ready to receive traffic -> Option A
Quick Check:
Readiness probe = container readiness [OK]
Hint: Readiness probe controls traffic flow to containers [OK]
Common Mistakes:
Confusing readiness probe with liveness probe
Thinking readiness probe restarts containers
Assuming readiness probe monitors resource usage
2. Which of the following is a valid way to define a readiness probe in a Kubernetes pod spec?
easy
A. readinessProbe:
httpGet:
path: /health
port: 8080
B. readinessProbe:
restartPolicy: Always
C. readinessProbe:
exec:
command: ["curl", "-f", "http://localhost:8080"]
D. readinessProbe:
tcpSocket:
port: 8080
Solution
Step 1: Review readiness probe types
Valid readiness probes include httpGet, tcpSocket, and exec commands.
Step 2: Check syntax correctness
readinessProbe:
httpGet:
path: /health
port: 8080 is now correctly indented. readinessProbe:
exec:
command: ["curl", "-f", "http://localhost:8080"] uses exec with correct command syntax as a list of strings. readinessProbe:
tcpSocket:
port: 8080 correctly defines tcpSocket with port. readinessProbe:
restartPolicy: Always is invalid because restartPolicy is not part of readiness probe.
Final Answer:
readinessProbe with tcpSocket and port -> Option D
Quick Check:
Valid readiness probe syntax = tcpSocket [OK]
Hint: Check indentation and valid probe keys for readiness probe [OK]
Common Mistakes:
Misplacing restartPolicy inside readinessProbe
Incorrect command format in exec probe
Wrong indentation causing YAML errors
3. Given this readiness probe configuration in a pod spec:
But Kubernetes always marks the pod as not ready. What is the most likely cause?
medium
A. The exec command syntax is invalid
B. The file /tmp/ready does not exist or is empty
C. initialDelaySeconds is too short
D. periodSeconds is too long
Solution
Step 1: Understand exec readiness probe behavior
The exec probe runs the command; it expects a zero exit code for success. If the file /tmp/ready does not exist, cat returns non-zero, causing failure.
Step 2: Check other options
Command syntax is valid. Timing values affect delay but not constant failure. So the missing or unreadable file is the cause.
Final Answer:
The file /tmp/ready does not exist or is empty -> Option B
5. You want to ensure your web server container only receives traffic after it finishes loading configuration and opens port 8080. Which readiness probe setup best achieves this?
hard
A. Use an exec readiness probe that runs a script checking config file and port status
B. Use an HTTP GET readiness probe on path /health with periodSeconds set to 1
C. Use a TCP socket readiness probe on port 8080 with initialDelaySeconds set to 10
D. Use a liveness probe instead of readiness probe to check port 8080
Solution
Step 1: Analyze readiness probe requirements
The container must be ready only after config is loaded and port is open. TCP socket or HTTP GET alone cannot check config loading.
Step 2: Evaluate probe options
Use a TCP socket readiness probe on port 8080 with initialDelaySeconds set to 10 checks only port open after delay, Use an HTTP GET readiness probe on path /health with periodSeconds set to 1 checks HTTP path frequently but not config. Use an exec readiness probe that runs a script checking config file and port status runs a script that can verify both config and port, making it the best choice. Use a liveness probe instead of readiness probe to check port 8080 is wrong because liveness probes do not control traffic routing.
Final Answer:
Use an exec readiness probe that runs a script checking config file and port status -> Option A
Quick Check:
Complex readiness checks need exec probe [OK]
Hint: Use exec probe for multi-condition readiness checks [OK]
Common Mistakes:
Using liveness probe instead of readiness probe
Relying only on TCP or HTTP probes for config readiness
Ignoring initialDelaySeconds impact on readiness
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.