In Kubernetes, liveness probes periodically check whether a container is still running correctly. If a probe fails, Kubernetes kills and restarts the container, restoring application availability without manual intervention.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Basic Docker Behavior
When you run an application in Docker, any crash stops the container until you restart it manually:nginx process crashes:
Kubernetes Automatic Restarts
Kubernetes continuously monitors container exit codes and restarts crashed containers automatically:Without a liveness probe, Kubernetes cannot detect hung or unresponsive applications that have not exited.
Introducing Liveness Probes
A liveness probe defines how Kubernetes determines container health. You choose one of three probe types:| Probe Type | Use Case | Configuration Snippet |
|---|---|---|
| HTTP GET | Web services | httpGet with path and port |
| TCP Socket | TCP-based protocols | tcpSocket with port |
| Exec | Custom commands/checks | exec with a command array |
HTTP Liveness Probe Example
initialDelaySeconds: 15
Waits 15 seconds before the first health check.periodSeconds: 10
Probes every 10 seconds.failureThreshold: 3
Restarts the container after three consecutive failures.