K8s by Example: Lifecycle Hooks
| Lifecycle hooks run at container start ( |
| pod-lifecycle.yaml | |
| Hooks are defined in the | |
| pod-poststart.yaml | |
|
| |
| pod-prestop.yaml | |
|
| |
| pod-termination.yaml | |
| Pod termination sequence: 1) Pod marked terminating, 2) Removed from Service endpoints (parallel with preStop), 3) preStop runs, 4) SIGTERM sent, 5) Wait for graceful shutdown, 6) SIGKILL after terminationGracePeriodSeconds. | |
| pod-http-hooks.yaml | |
| HTTP hooks call an endpoint instead of running a command. Response status doesn’t matter, only connection errors cause failure. Useful for distroless or minimal containers without shell. | |
| pod-grace-period.yaml | |
| The | |
| terminal | |
| Debug hooks with events. postStart failures appear in Pod events. preStop failures are harder to catch, so add logging in your hook script. Hooks don’t have stdout/stderr. | |