A container restarts because the process exits – or because the kubelet kills it. With a liveness probe that is too strict, it is the kubelet: the log ends in the middle of startup, without an error. The Unhealthy and Killing events show which case you have.
Symptom
kubectl -n tag05 get pods -l app=langsam NAME READY STATUS RESTARTS AGE langsam-6b8fb65674-95vvb 1/1 Running 2 (15s ago) 75s
1/1 and still restarts: without a readiness probe, the container counts as ready immediately, even if it doesn't answer yet.
Diagnosis
Filter the events for Unhealthy and Killing, then read the log of the killed run.
kubectl -n tag05 events --for $(kubectl -n tag05 get pod -l app=langsam -o name) \ | grep -E 'Unhealthy|Killing' | cut -c1-88 kubectl -n tag05 logs deploy/langsam --previous 21s (x2 over 51s) Normal Killing Pod/langsam-6b8fb65674-95vvb Container app failed liveness probe, will be restarted 1s (x7 over 61s) Warning Unhealthy Pod/langsam-6b8fb65674-95vvb Liveness probe failed: Get "http://10.42.2.19:8080/healthz": dial tcp ... Lade Daten (dauert 40 Sekunden) ...
Causes
KillingThe probe gives up before startup is done
The application needs 40 seconds to start. After initialDelaySeconds 10 plus three failed attempts at 5 s each – 25 seconds – the kubelet kills the container.
Exit 137 without OOMKilledKilled from outside
The log ends without an error message. sh as PID 1 ignores SIGTERM, so after the grace period SIGKILL follows: exit code 137, but without Reason OOMKilled.
dial tcp …:80The probe checks the wrong port
The probe checks port 80, httpd listens on 8080. The container runs fine and still gets killed again and again.
11s (x2 over 31s) Normal Killing Pod/waechter-5bf8fb5d6d-89w29 Container app failed liveness probe, will be restarted 1s (x7 over 41s) Warning Unhealthy Pod/waechter-5bf8fb5d6d-89w29 Liveness probe failed: dial tcp 10.42.2.23:80: ...
Fix
kubectl -n tag05 patch deploy langsam -p '
spec:
template:
spec:
containers:
- name: app
startupProbe:
httpGet: {path: /healthz, port: 8080}
periodSeconds: 5
failureThreshold: 18'
kubectl -n tag05 rollout status deploy/langsam
kubectl -n tag05 get pods -l app=langsam
NAME READY STATUS RESTARTS AGE
langsam-79b659cc47-d22tt 1/1 Running 0 46s
Don't: Setting a huge initialDelaySeconds. A slow start is what the startupProbe is for.
Debugging Kubernetes, day 5: six crashes from a typo to readOnlyRootFilesystem, with a drill to reproduce each one.
Go to day 5 →
FAQ
Liveness or readiness – what is the difference?
Liveness restarts the container when the process hangs. Readiness restarts nothing; it only takes the Pod out of the Service.
Should the liveness probe check the database?
No. A liveness probe that depends on dependencies such as the database turns a DB outage into a restart storm.
Why do the probes only fail under load?
Probes with timeoutSeconds 1 fail when the application is busy and doesn't answer in time.