preStop hook failed during pod termination
Production Risk
Graceful shutdown may be incomplete; in-flight requests may be dropped or queues not flushed.
PreStopHookError occurs when the preStop lifecycle hook fails or times out during pod termination. Unlike postStart, a preStop failure does not prevent the container from being killed — Kubernetes continues with termination regardless. However, a failing preStop hook means graceful shutdown logic (flushing queues, deregistering from service discovery) was not executed.
- 1preStop exec command exits with non-zero code
- 2preStop HTTP endpoint returns an error
- 3preStop hook takes longer than terminationGracePeriodSeconds
Observed in events during pod deletion; may cause incomplete graceful shutdown.
kubectl describe pod mypod | grep -i "prestop|lifecycle" kubectl get events --field-selector involvedObject.name=mypod | grep -i prestop
expected output
Warning FailedPreStopHook ... Exec lifecycle hook failed
Fix
Ensure preStop command is idempotent and fast
WHEN preStop hook is failing or timing out
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 5"]
# Increase grace period if hook needs more time
terminationGracePeriodSeconds: 60Why this works
A simple sleep in preStop gives load balancers time to deregister the pod before shutdown.
Kubernetes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev