Chapter 1 showed the kubelet restarting a container when its process exits. A process can also be alive and useless: deadlocked, out of file handles, stuck in a loop. From the outside it looks fine. A liveness probe lets the kubelet ask.
The check
containers:
- name: web
image: nginx:1.27
livenessProbe:
httpGet:
path: /
port: 80
periodSeconds: 10
failureThreshold: 3Every periodSeconds the kubelet sends GET / to the container's port. Status 200 to 399 is a pass. Anything else, or no answer within timeoutSeconds (default 1), is a failure.
The Pod stays. Its IP stays. Only the container is killed and started again, and RESTARTS goes up by one.
Three kinds of probe
| Kind | Passes when |
|---|---|
httpGet | the response status is 200 to 399 |
tcpSocket | something accepts a connection on port |
exec | the command exits 0 inside the container |
Reading it
kubectl describe pod prints the probe on one line and the failures as Events:
Liveness: http-get http://:80/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
Events:
Warning Unhealthy Liveness probe failed: HTTP probe failed with statuscode: 404
Normal Killing Container web failed liveness probe, will be restartedA rising RESTARTS column together with Unhealthy events is a liveness problem, and the message says why.