Kubernetes liveness probe `statuscode: 404` killed a healthy pod (CrashLoopBackOff)
The web deployment in our prod namespace was in CrashLoopBackOff on EKS 1.28. The container logs showed a clean startup and then a SIGTERM about 30 seconds later. No exception, no panic, just a tidy shutdown. That pattern usually means something outside the app is killing it.
I started with kubectl logs --previous, because the current container had only been up for 40 seconds. The previous container's log ended with Shutting down ExecutorService and nothing after it, which ruled out an unhandled exception and sent me looking at kubelet events instead. Should have gone there first.
## What the events were saying
bash
kubectl describe pod web-6c8b7d54f9-mn4kp -n prod | tail -20
kubectl get events -n prod --sort-by=.lastTimestamp | grep web-6c8b7d54f9-mn4kp
Warning Unhealthy 3s (x6 over 53s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 404
Normal Killing 3s kubelet Container web failed liveness probe, will be restarted
Normal Pulled 2s kubelet Container image "web:2.14.3" already present on machine
There it was. The liveness probe was failing with 404, and the kubelet did exactly what we told it to: kill and restart.
## The probe was checking the wrong route
The manifest had this:
yaml
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
But the service is Spring Boot with Actuator, and we'd exposed health under a management port with a context path:
management.server.port: 8081
management.endpoints.web.base-path: /actuator
So /health on 8080 returned 404 from the app itself. The app was fine; the probe was just asking the wrong question. kubectl logs --previous showed the shutdown hook running every time, which is why it looked so polite.
Before changing it I checked from inside the pod:
bash
kubectl exec -it web-6c8b7d54f9-mn4kp -n prod -- curl -i localhost:8081/actuator/health/liveness
HTTP/1.1 200
{"status":"UP","groups":["liveness"]}
Actuator has separate /actuator/health/liveness and /actuator/health/readiness groups, so I pointed the probe at those rather than the aggregate health endpoint. That distinction matters: aggregated health includes disk space checks, and we didn't want a full disk to trigger a restart loop when the process was otherwise serving fine.
## startupProbe for slow starters
While in there I added a startupProbe, because initialDelaySeconds: 10 was always going to be fragile on a cold node:
yaml
startupProbe:
httpGet:
path: /actuator/health/liveness
port: 8081
failureThreshold: 30
periodSeconds: 5
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8081
periodSeconds: 10
failureThreshold: 3
The liveness probe doesn't run until startup succeeds, so a slow boot no longer gets punished. We have one service that takes 90 seconds to warm a cache and this fixed it too.
## The follow-up
I checked the other deployments and found two more probes pointing at /health. One was harmless because the route happened to exist; the other was failing silently and nobody had noticed because the pod hadn't been drained yet. Checking kubectl get events early would have saved most of the morning, but I went straight to logs and spent twenty minutes reading a perfectly healthy application.