Kubernetes restarts a running container because the health check answers too slowly
Your error
Liveness probe failed: Get "http://10.244.1.17:8080/healthz": context deadline exceeded (Client.Timeout exceeded while awaiting headers)1 more line it can showFix it fast
Most common cause, 1 of 2The health route needs more than the 1-second default
Give the probe a timeout that covers the route's slow moments, and make the route itself cheap.
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3Short answer
Liveness probe failed: context deadline exceeded (Client.Timeout exceeded while awaiting headers) means the kubelet got no response headers within timeoutSeconds, which defaults to 1 second. Either the health route is slower than that, or it waits on a database or another service. Time the route, raise timeoutSeconds, and keep liveness checks local. Applies to Kubernetes 1.37.
Which cause do you have?
Forward the pod's port and time the health route a few times, once while the app is idle and once while its database or cache is busy. The numbers tell you whether the route is always near one second or only slow when a dependency is slow.
kubectl port-forward pod/web-7d9c6b5f4-x2kqp 8080:8080 &
curl -s -o /dev/null -w "%{time_total}\n" http://127.0.0.1:8080/healthzThen find the line you see in this list and open its fix:
- 1The health route needs more than the 1-second default
curl reports a time close to or above 1 second even when nothing else is busy - 2The liveness route waits on a database or another service
The route is fast when idle, and the timeouts and restarts start together with slow queries or a dependency outage
What does the error look like?
Liveness probe failed: Get "http://10.244.1.17:8080/healthz": context deadline exceeded (Client.Timeout exceeded while awaiting headers)Readiness probe failed: Get "http://10.244.1.17:8080/healthz": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Cause 1 of 2
The health route needs more than the 1-second default
You seecurl reports a time close to or above 1 second even when nothing else is busy
Check
The kubelet's HTTP probe uses a Go client whose timeout equals timeoutSeconds. The Pod API sets that field to 1 second unless you change it, so a route that regularly takes a second or more fails with context deadline exceeded and, after failureThreshold misses, the container is killed.
kubectl get pod web-7d9c6b5f4-x2kqp -o jsonpath="{.spec.containers[0].livenessProbe}"Fix
Give the probe a timeout that covers the route's slow moments, and make the route itself cheap. Raising failureThreshold as well stops a single slow answer from restarting the pod.
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3Verify
kubectl describe pod shows no new Unhealthy events and the RESTARTS column stops rising.
kubectl get pod web-7d9c6b5f4-x2kqp -wConfirmed by kubernetes.io
Cause 2 of 2
The liveness route waits on a database or another service
You seeThe route is fast when idle, and the timeouts and restarts start together with slow queries or a dependency outage
Check
A liveness check that opens a database connection or calls another API inherits that service's delays. Kubernetes warns that a badly designed liveness probe restarts containers under high load and spreads failure across pods. Look at what the handler does.
kubectl logs deploy/web --since=10m | grep -i healthzFix
Split the checks. Let liveness answer only whether the process itself works, and put the dependency checks behind a separate readiness route, which takes the pod out of the Service without restarting it.
livenessProbe:
httpGet:
path: /livez
port: 8080
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /readyz
port: 8080
timeoutSeconds: 3Verify
During the next slow period the pod shows READY 0/1 for a while instead of restarting.
kubectl get pods -l app=webConfirmed by kubernetes.io
How do I stop it coming back?
- Set timeoutSeconds on every probe explicitly; never rely on the 1-second default for HTTP routes.
- Keep the liveness handler free of network calls and test its response time in CI.
- Alert on container restart counts so probe-driven restarts show up before users notice.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro.