Bird
Raised Fist0
Kubernetesdevops~10 mins

Probe failure and container restart behavior in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Probe failure and container restart behavior
Pod starts container
↓
Kubelet runs probes
↓
Probe success?
No→Failure count increments
↓
Failure count >= threshold?
↓
Container runs normally
↓
Failure count >= threshold?
Yes→Container restart triggered
No↓
Continue monitoring probes
This flow shows how Kubernetes runs health probes on containers, counts failures, and restarts containers when failures reach a limit.
Execution Sample
Kubernetes
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  failureThreshold: 3
  periodSeconds: 5
Defines a liveness probe that checks /healthz every 5 seconds and restarts container after 3 failures.
Process Table
Check NumberProbe ResultFailure CountRestart TriggeredAction
1Success0NoContainer continues running
2Failure1NoMonitor continues
3Failure2NoMonitor continues
4Failure3YesContainer restart triggered
5Success0NoContainer runs after restart
💡 After 3 consecutive failures, container restarts and failure count resets
Status Tracker
VariableStartAfter Check 1After Check 2After Check 3After Check 4After Check 5
failureCount001230
containerStateRunningRunningRunningRunningRestartingRunning
Key Moments - 3 Insights
Why does the failure count reset after the container restarts?
Because when the container restarts (see row 4 in execution_table), Kubernetes resets the failure count to zero to start fresh monitoring.
Does a single probe failure immediately restart the container?
No, the container restarts only after failureCount reaches the failureThreshold (3 in this example), as shown in rows 2-4.
What happens if a probe succeeds after some failures?
The failure count resets to zero (see row 5), so the container is considered healthy again.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the failureCount after the 3rd probe check?
A1
B2
C3
D0
💡 Hint
Check the 'Failure Count' column at row 3 in the execution_table.
At which check number does the container restart get triggered?
A2
B3
C4
D5
💡 Hint
Look at the 'Restart Triggered' column in the execution_table.
If the failureThreshold was set to 2, when would the container restart occur?
AAfter check 2
BAfter check 3
CAfter check 4
DAfter check 5
💡 Hint
Compare failureCount with failureThreshold in the execution_table rows.
Concept Snapshot
Kubernetes probes check container health periodically.
Failures increment a failureCount.
When failureCount reaches failureThreshold, container restarts.
Success resets failureCount to zero.
This ensures unhealthy containers get restarted automatically.
Full Transcript
Kubernetes uses probes like livenessProbe to check if a container is healthy. Each probe runs periodically. If a probe fails, Kubernetes increases a failure count. When this count reaches a set threshold, Kubernetes restarts the container to fix issues. If a probe succeeds, the failure count resets to zero. This cycle helps keep containers running smoothly by restarting them only after repeated failures, not just one failure.

Practice

(1/5)
1. What happens when a Kubernetes liveness probe fails for a container?
easy
A. Traffic to the container is stopped but it is not restarted.
B. The container is restarted by Kubernetes.
C. The container continues running without changes.
D. The container is removed permanently.

Solution

  1. Step 1: Understand liveness probe purpose

    Liveness probes check if a container is alive and healthy.
  2. Step 2: Effect of liveness probe failure

    If the liveness probe fails, Kubernetes restarts the container to fix the issue.
  3. Final Answer:

    The container is restarted by Kubernetes. -> Option B
  4. Quick Check:

    Liveness probe failure = container restart [OK]
Hint: Liveness probe failure always triggers container restart [OK]
Common Mistakes:
  • Confusing liveness with readiness probe effects
  • Thinking container is deleted permanently
  • Assuming no action on failure
2. Which of the following is the correct YAML snippet to define a liveness probe using HTTP GET on path /health at port 8080?
easy
A. livenessProbe: httpGet: path: health port: 8080 initialDelaySeconds: 5 periodSeconds: 10
B. livenessProbe: exec: command: ["curl", "/health"] initialDelaySeconds: 5 periodSeconds: 10
C. livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10
D. livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10

Solution

  1. Step 1: Check HTTP GET probe syntax

    The correct syntax uses httpGet with path starting with a slash and port as a number.
  2. Step 2: Validate each option

    livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 correctly uses /health and port 8080. livenessProbe: exec: command: ["curl", "/health"] initialDelaySeconds: 5 periodSeconds: 10 uses exec with curl incorrectly. livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10 uses tcpSocket which is different. livenessProbe: httpGet: path: health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 misses the leading slash in path.
  3. Final Answer:

    livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 -> Option D
  4. Quick Check:

    HTTP GET probe with correct path and port = livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 [OK]
Hint: HTTP path must start with '/' and port is a number [OK]
Common Mistakes:
  • Missing leading slash in path
  • Using exec command incorrectly
  • Confusing tcpSocket with httpGet
3. Given this pod spec snippet, what happens if the readiness probe fails but the liveness probe passes?
readinessProbe:
  httpGet:
    path: /ready
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 10
livenessProbe:
  httpGet:
    path: /live
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 10
medium
A. The container is restarted immediately.
B. The container is deleted and recreated.
C. The container is marked not ready and removed from service endpoints.
D. Nothing happens; container continues serving traffic.

Solution

  1. Step 1: Understand readiness probe role

    Readiness probe controls if the container receives traffic by marking it ready or not.
  2. Step 2: Effect of readiness probe failure

    If readiness probe fails but liveness probe passes, container stays running but is removed from service endpoints, so no traffic is sent to it.
  3. Final Answer:

    The container is marked not ready and removed from service endpoints. -> Option C
  4. Quick Check:

    Readiness fail = no traffic, container runs [OK]
Hint: Readiness failure stops traffic, liveness failure restarts container [OK]
Common Mistakes:
  • Confusing readiness failure with container restart
  • Thinking container is deleted
  • Assuming no effect on traffic
4. You notice your container keeps restarting frequently. The liveness probe is configured with initialDelaySeconds: 5 and periodSeconds: 10. What is a likely cause and fix?
medium
A. The initial delay is too short; increase initialDelaySeconds to allow startup time.
B. The period is too long; decrease periodSeconds to check faster.
C. The probe path is incorrect; change it to /healthz.
D. The container image is corrupted; rebuild the image.

Solution

  1. Step 1: Analyze probe timing settings

    If initialDelaySeconds is too short, the probe runs before the app is ready, causing false failures.
  2. Step 2: Adjust initial delay

    Increasing initialDelaySeconds gives the container time to start before probing, preventing unnecessary restarts.
  3. Final Answer:

    The initial delay is too short; increase initialDelaySeconds to allow startup time. -> Option A
  4. Quick Check:

    Short initialDelay causes early probe failure [OK]
Hint: Increase initialDelaySeconds if container restarts too soon [OK]
Common Mistakes:
  • Changing periodSeconds instead of initialDelaySeconds
  • Assuming probe path is always wrong
  • Blaming container image without checking probes
5. You have a container with both readiness and liveness probes. The readiness probe fails intermittently, but the liveness probe always passes. How should Kubernetes behave and what is the best way to improve user experience?
hard
A. Kubernetes removes the pod from service during readiness failure but does not restart it; improve by tuning readiness probe thresholds.
B. Kubernetes restarts the container on readiness failure; improve by disabling readiness probe.
C. Kubernetes ignores readiness probe failures if liveness passes; no action needed.
D. Kubernetes deletes the pod on readiness failure; improve by increasing liveness probe timeout.

Solution

  1. Step 1: Understand probe roles on intermittent readiness failure

    Readiness failure removes pod from service endpoints but does not restart container if liveness passes.
  2. Step 2: Improve user experience by tuning readiness probe

    Tuning thresholds like failureThreshold or periodSeconds reduces false negatives and prevents unnecessary traffic disruption.
  3. Final Answer:

    Kubernetes removes the pod from service during readiness failure but does not restart it; improve by tuning readiness probe thresholds. -> Option A
  4. Quick Check:

    Readiness fail = no traffic; tune probe to reduce false failures [OK]
Hint: Tune readiness probe to avoid false failures and traffic loss [OK]
Common Mistakes:
  • Thinking readiness failure restarts container
  • Disabling readiness probe instead of tuning
  • Ignoring intermittent failures
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