Bird
Raised Fist0
Kubernetesdevops~10 mins

Readiness probe concept in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Readiness probe concept
Pod starts
↓
Kubelet runs readiness probe
↓
Probe sends request to container
↓
Container responds
↓
Success?
No→Pod marked NOT ready
↓
Retry probe after delay
+--> Yes↓
Pod marked READY
↓
Traffic routed to Pod
The readiness probe checks if a container is ready to receive traffic. If it succeeds, the pod is marked ready and receives traffic. If it fails, the pod is marked not ready and traffic is stopped.
Execution Sample
Kubernetes
readinessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
This readiness probe sends an HTTP GET request to /health on port 8080 every 10 seconds, starting 5 seconds after the container starts.
Process Table
StepActionProbe ResultPod Readiness StateEffect
1Pod starts, wait 5 secondsNo probe yetNot ReadyNo traffic sent
2Send HTTP GET /healthSuccessReadyPod receives traffic
3Wait 10 secondsNo probeReadyTraffic continues
4Send HTTP GET /healthFailureNot ReadyTraffic stopped
5Wait 10 secondsNo probeNot ReadyNo traffic
6Send HTTP GET /healthSuccessReadyTraffic resumes
💡 Probe continues periodically; pod readiness state updates based on probe success or failure.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 6
Pod ReadinessNot ReadyReadyNot ReadyReady
Probe ResultNoneSuccessFailureSuccess
Key Moments - 3 Insights
Why is the pod not ready immediately after starting?
Because the readiness probe has an initial delay (5 seconds) before it starts checking, as shown in step 1 of the execution_table.
What happens to traffic when the readiness probe fails?
The pod is marked Not Ready and stops receiving traffic, as shown in step 4 where the probe fails and traffic is stopped.
Does the pod stay not ready forever after a failure?
No, the probe runs periodically and if it succeeds later (step 6), the pod becomes ready again and traffic resumes.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the pod readiness state after the first successful probe?
ANot Ready
BReady
CUnknown
DTerminated
💡 Hint
Check Step 2 in the execution_table where the probe result is Success.
At which step does the pod stop receiving traffic?
AStep 4
BStep 6
CStep 2
DStep 1
💡 Hint
Look at the Effect column in the execution_table for when traffic is stopped.
If the initialDelaySeconds was set to 0, what would change in the execution_table?
APod would skip readiness checks
BPod would never become ready
CProbe would run immediately at Step 1
DPod would be ready before starting
💡 Hint
Refer to Step 1 where currently no probe runs due to initial delay.
Concept Snapshot
Readiness probe checks if a container is ready to serve traffic.
It runs periodically after an initial delay.
If probe succeeds, pod is marked Ready and receives traffic.
If probe fails, pod is Not Ready and traffic stops.
Common probe types: HTTP GET, TCP socket, command execution.
Configured in pod spec under readinessProbe.
Full Transcript
A readiness probe in Kubernetes is a check that tells if a container inside a pod is ready to accept traffic. When a pod starts, Kubernetes waits for a configured initial delay before running the probe. The probe sends a request, like an HTTP GET, to the container. If the container responds successfully, the pod is marked ready and traffic is sent to it. If the probe fails, the pod is marked not ready and traffic is stopped. The probe runs repeatedly at set intervals to update the pod's readiness state. This helps Kubernetes only send traffic to pods that are fully ready to handle it.

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

  1. Step 1: Understand readiness probe role

    A readiness probe checks if a container is ready to accept requests, preventing traffic to unready containers.
  2. Step 2: Compare with other options

    Other options describe different Kubernetes features: restarts (liveness probe), monitoring (metrics), and updates (deployments).
  3. Final Answer:

    To tell Kubernetes when a container is ready to receive traffic -> Option A
  4. 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

  1. Step 1: Review readiness probe types

    Valid readiness probes include httpGet, tcpSocket, and exec commands.
  2. 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.
  3. Final Answer:

    readinessProbe with tcpSocket and port -> Option D
  4. 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:
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
What happens if the HTTP GET request to /ready returns status 503?
medium
A. Kubernetes ignores the failure and continues sending traffic
B. Kubernetes restarts the container immediately
C. Kubernetes marks the container as not ready and stops sending traffic
D. Kubernetes deletes the pod

Solution

  1. Step 1: Understand readiness probe failure effect

    If the readiness probe fails (like HTTP 503), Kubernetes marks the container as not ready and stops routing traffic to it.
  2. Step 2: Differentiate from liveness probe

    Liveness probe failure causes restarts, but readiness probe failure only affects traffic routing, not container lifecycle.
  3. Final Answer:

    Kubernetes marks the container as not ready and stops sending traffic -> Option C
  4. Quick Check:

    Readiness failure = no traffic [OK]
Hint: Readiness failure stops traffic, does not restart container [OK]
Common Mistakes:
  • Confusing readiness probe failure with liveness probe failure
  • Assuming container restarts on readiness failure
  • Thinking pod gets deleted on readiness failure
4. You defined this readiness probe in your pod YAML:
readinessProbe:
  exec:
    command: ["cat", "/tmp/ready"]
  initialDelaySeconds: 5
  periodSeconds: 10
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

  1. 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.
  2. 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.
  3. Final Answer:

    The file /tmp/ready does not exist or is empty -> Option B
  4. Quick Check:

    Exec probe success = command exit code 0 [OK]
Hint: Exec probe needs command to succeed (exit code 0) [OK]
Common Mistakes:
  • Assuming timing values cause readiness failure
  • Misunderstanding exec command success criteria
  • Ignoring file existence for exec probes
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

  1. 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.
  2. 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.
  3. Final Answer:

    Use an exec readiness probe that runs a script checking config file and port status -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard