Graceful Shutdown Is Not a preStop Hook
Kubernetes graceful shutdown is often reduced to adding a preStop hook and waiting before exit. That treats termination as a container detail, although availability depends on several systems changing state in the correct order.
Graceful shutdown is an operating contract. Applications, workload configuration, traffic infrastructure, and rollout policy must agree on when new work stops and how existing work finishes.
What matters
- Traffic withdrawal: Stop accepting new requests before the process exits, while allowing established work to drain.
- Signal handling: The application must handle termination directly and keep readiness, shutdown, and background workers consistent.
- Shared time budget:
preStopexecution and application shutdown consume the same termination grace period. Arbitrary sleeps reduce the time available for useful cleanup. - Dependency behavior: Clients, gateways, queues, and service proxies need compatible retry and connection-draining semantics.
- Operational verification: Test rollouts, scale-downs, drains, and forced termination separately. A clean deployment does not prove safe node maintenance.
Recommendation
Define standardized shutdown profiles for common workload classes. Include readiness behavior, grace periods, rollout settings, and observable termination outcomes.
Use preStop only for actions the application cannot perform itself. Reliable termination comes from coordinated lifecycle ownership, not from delaying process exit.