What if your app could fix itself before you even notice a problem?
Why Probe failure and container restart behavior in Kubernetes? - Purpose & Use Cases
Imagine you run a website on a server, and sometimes it stops working properly. You have to check it yourself every few minutes to see if it's still running. If it's down, you restart it manually. This takes a lot of time and you might miss the problem, causing your users to see errors.
Manually checking if a service is healthy is slow and tiring. You can forget to check, or restart the wrong thing. This causes downtime and unhappy users. Also, fixing problems only after they happen means lost time and trust.
Kubernetes probes automatically check if your container is healthy. If a probe fails, Kubernetes can restart the container for you. This means your app recovers quickly without you lifting a finger, keeping your service reliable and smooth.
Check service status every 5 minutes and restart if down: systemctl status myapp if not running: systemctl restart myapp
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5This lets your applications heal themselves automatically, reducing downtime and freeing you to focus on building new features.
A popular online store uses Kubernetes probes to detect when their payment service hangs. When a probe fails, Kubernetes restarts the service instantly, so customers never face payment errors.
Manual health checks are slow and error-prone.
Kubernetes probes automate health monitoring and recovery.
This leads to more reliable apps and less manual work.
Practice
Solution
Step 1: Understand liveness probe purpose
Liveness probes check if a container is alive and healthy.Step 2: Effect of liveness probe failure
If the liveness probe fails, Kubernetes restarts the container to fix the issue.Final Answer:
The container is restarted by Kubernetes. -> Option BQuick Check:
Liveness probe failure = container restart [OK]
- Confusing liveness with readiness probe effects
- Thinking container is deleted permanently
- Assuming no action on failure
/health at port 8080?Solution
Step 1: Check HTTP GET probe syntax
The correct syntax useshttpGetwithpathstarting with a slash andportas a number.Step 2: Validate each option
livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 correctly uses/healthand 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.Final Answer:
livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 -> Option DQuick Check:
HTTP GET probe with correct path and port = livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 5 periodSeconds: 10 [OK]
- Missing leading slash in path
- Using exec command incorrectly
- Confusing tcpSocket with httpGet
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /live
port: 80
initialDelaySeconds: 5
periodSeconds: 10Solution
Step 1: Understand readiness probe role
Readiness probe controls if the container receives traffic by marking it ready or not.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.Final Answer:
The container is marked not ready and removed from service endpoints. -> Option CQuick Check:
Readiness fail = no traffic, container runs [OK]
- Confusing readiness failure with container restart
- Thinking container is deleted
- Assuming no effect on traffic
initialDelaySeconds: 5 and periodSeconds: 10. What is a likely cause and fix?Solution
Step 1: Analyze probe timing settings
IfinitialDelaySecondsis too short, the probe runs before the app is ready, causing false failures.Step 2: Adjust initial delay
IncreasinginitialDelaySecondsgives the container time to start before probing, preventing unnecessary restarts.Final Answer:
The initial delay is too short; increaseinitialDelaySecondsto allow startup time. -> Option AQuick Check:
Short initialDelay causes early probe failure [OK]
- Changing periodSeconds instead of initialDelaySeconds
- Assuming probe path is always wrong
- Blaming container image without checking probes
Solution
Step 1: Understand probe roles on intermittent readiness failure
Readiness failure removes pod from service endpoints but does not restart container if liveness passes.Step 2: Improve user experience by tuning readiness probe
Tuning thresholds like failureThreshold or periodSeconds reduces false negatives and prevents unnecessary traffic disruption.Final Answer:
Kubernetes removes the pod from service during readiness failure but does not restart it; improve by tuning readiness probe thresholds. -> Option AQuick Check:
Readiness fail = no traffic; tune probe to reduce false failures [OK]
- Thinking readiness failure restarts container
- Disabling readiness probe instead of tuning
- Ignoring intermittent failures
Ready to prove it?
Pass the test and this pattern moves unknown
