0
0
Kubernetesdevops~10 mins

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

Choose your learning style9 modes available
Process Flow - Liveness probe concept
Pod starts running
Kubelet sends liveness probe
Probe checks container health
Healthy?
YesWait for next probe
No
Kubelet kills container
Container restarts
Back to sending liveness probe
The liveness probe checks if a container is alive. If not, Kubernetes restarts it to keep the app healthy.
Execution Sample
Kubernetes
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
This YAML config tells Kubernetes to check the /healthz URL on port 8080 every 10 seconds after waiting 5 seconds initially.
Process Table
StepActionProbe ResultKubelet DecisionContainer State
1Pod starts, wait 5 secondsNo probe yetWaitRunning
2Send liveness probe (GET /healthz)Success (200 OK)Do nothingRunning
3Wait 10 secondsNo probeWaitRunning
4Send liveness probe (GET /healthz)Failure (timeout)Kill containerTerminating
5Container restartsNo probe yetWaitStarting
6Send liveness probe (GET /healthz)Success (200 OK)Do nothingRunning
💡 Container is healthy again, so liveness probes continue periodically.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 5After Step 6
Container StateRunningRunningTerminatingStartingRunning
Probe ResultNoneSuccessFailureNoneSuccess
Key Moments - 3 Insights
Why does Kubernetes kill the container after a failed liveness probe?
Because the liveness probe failure means the container is unhealthy or stuck, so Kubernetes restarts it to fix the problem (see execution_table step 4).
What happens during the initialDelaySeconds period?
Kubernetes waits before sending the first liveness probe to give the container time to start up (see execution_table step 1).
Does a successful liveness probe restart the container?
No, a successful probe means the container is healthy, so Kubernetes does nothing and continues monitoring (see execution_table step 2 and 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the container state after step 4?
ARunning
BTerminating
CStarting
DStopped
💡 Hint
Check the 'Container State' column at step 4 in the execution_table.
At which step does Kubernetes restart the container?
AStep 4
BStep 3
CStep 5
DStep 2
💡 Hint
Look for the step where the container state changes to 'Starting' in the execution_table.
If initialDelaySeconds was set to 0, what would change in the execution table?
AStep 1 would send a probe immediately
BContainer would never restart
CProbe results would always be failure
DContainer state would start as Terminating
💡 Hint
Refer to the description of initialDelaySeconds and step 1 in the execution_table.
Concept Snapshot
Liveness Probe in Kubernetes:
- Checks if container is alive
- Configured with httpGet, tcpSocket, or exec
- initialDelaySeconds waits before first check
- periodSeconds sets check frequency
- Failure causes container restart
- Keeps app healthy automatically
Full Transcript
A liveness probe is a health check Kubernetes uses to see if a container is alive. When a pod starts, Kubernetes waits for initialDelaySeconds before sending the first probe. It then sends probes every periodSeconds. If the probe succeeds, Kubernetes does nothing and waits for the next check. If the probe fails, Kubernetes kills the container and restarts it. This cycle repeats to keep the application running smoothly. The YAML example shows a simple HTTP GET probe on /healthz at port 8080. The execution table traces the container state and probe results step-by-step, showing how Kubernetes reacts to success and failure. Key points include the wait before the first probe, the restart on failure, and no action on success. This helps beginners understand how liveness probes maintain container health automatically.