The FailedPreStopHook warning occurs when a container's preStop lifecycle hook fails during pod termination. Unlike postStart failures, this doesn't prevent termination—the pod will still be killed.
The FailedPreStopHook warning appears when a pod's preStop lifecycle hook fails to execute successfully during termination. PreStop hooks are designed to perform graceful shutdown tasks like draining connections, flushing logs, or deregistering from service discovery. Important: A preStop hook failure does NOT prevent pod termination. The pod will still be killed after the terminationGracePeriodSeconds expires. The warning is informational—it tells you your graceful shutdown logic didn't work as intended. PreStop hooks execute synchronously—Kubernetes waits for the hook to complete before sending SIGTERM to the container. If the hook takes too long, the entire grace period may be consumed, leaving no time for the application's own shutdown handling.
View termination events to see preStop failures:
kubectl describe pod <pod-name>Look for:
Warning FailedPreStopHook Exec lifecycle hook failedCommon syntax errors cause silent failures. Ensure proper array format:
# Correct
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "nginx -s quit"]
# Wrong - extra quotes
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "'nginx -s quit'"]Ensure the grace period exceeds preStop duration plus shutdown time:
spec:
terminationGracePeriodSeconds: 60 # Default is 30
containers:
- name: app
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 10 && /shutdown.sh"]PreStop output doesn't appear in kubectl logs. Redirect to container stdout:
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
echo "Starting graceful shutdown" >> /proc/1/fd/1
/shutdown.sh 2>&1 >> /proc/1/fd/1Trigger termination to test your preStop hook:
# Delete pod and watch events
kubectl delete pod <pod-name> &
kubectl get events -w --field-selector involvedObject.name=<pod-name>Note: PreStop hooks only run on forced termination, not when a container exits successfully on its own.
PreStop hooks and SIGTERM handling have a race condition. The timeline is:
1. PreStop hook starts
2. Hook completes (or times out)
3. SIGTERM sent to container
4. App handles SIGTERM
5. SIGKILL at grace period end
If your hook runs for 25 seconds and grace period is 30 seconds, your app only has 5 seconds to handle SIGTERM before SIGKILL.
For load balancer scenarios, add a sleep in preStop to allow the load balancer to deregister the pod:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 15"]This gives the load balancer time to stop sending traffic before the application starts shutting down.
Service port already allocated
How to fix "Service port already allocated" in Kubernetes
minimum cpu usage per Container
How to fix "minimum cpu usage per Container" in Kubernetes
Failed to connect to server: connection refused (HTTP/2)
How to fix "HTTP/2 connection refused" error in Kubernetes
No subnets found for EKS cluster
How to fix "eks subnet not found" in Kubernetes
missing request for cpu in container
How to fix "missing request for cpu in container" in Kubernetes HPA