postStart lifecycle hook failed
Production Risk
Container loops through start/kill cycles; service is unavailable.
PostStartHookError occurs when the postStart lifecycle hook defined on a container exits with a non-zero code. Kubernetes kills the container when this happens, causing it to restart. The postStart hook runs immediately after the container starts, in parallel with the main process, so failures here prevent the container from reaching Running state.
- 1postStart exec command fails or exits with non-zero code
- 2postStart HTTP call returns an error or the endpoint is not yet ready
- 3Script referenced in postStart does not exist in the container image
Container restarts immediately after starting; describe shows PostStartHookError event.
kubectl describe pod mypod | grep -A 5 "Events:" # Warning FailedPostStartHook kubelet Exec lifecycle hook ([/bin/sh ...]) for # Container "myapp" in Pod "mypod" failed
expected output
Warning FailedPostStartHook ... Exec lifecycle hook failed
Fix 1
Test the postStart command manually
WHEN postStart exec hook is failing
# Run the container and test the hook command interactively kubectl run debug --image=myimage:tag --restart=Never -it --rm -- /bin/sh -c "/path/to/hook-script.sh; echo exit:$?"
Why this works
Tests the exact command in the hook to identify why it is failing.
Fix 2
Review and fix the lifecycle hook definition
WHEN Hook command or HTTP endpoint is misconfigured
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo 'started' > /tmp/started"]Why this works
Use simple, reliable commands in postStart hooks; avoid complex logic that can fail.
✕
Kubernetes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev