Running workloadsLesson 6 of 14
Graceful shutdown — going down without losing requests
Rollouts, scale-downs and node drains all end with "delete one pod". Here we follow the order in which that pod goes down without losing the requests it was handling. The full rollout flow is in Zero-Downtime Deploys (Rolling Update), and node maintenance is in Draining Nodes and Upgrading the Cluster.
Pods taking requests2
web-1 in-flight requests3
Grace time left—
Failed requests0
RequestWatchAppears in a later step
What you will learn
- Removal from the request targets and the stop signal happen at the same time
- Why preStop waits a few seconds
- What an app must do on SIGTERM
- After the grace period, SIGKILL forces a stop
Shutdown order at a glance
| Step | What happens | What the app or config must do |
|---|---|---|
| 1 | The pod becomes Terminating and the grace period starts | Raise terminationGracePeriodSeconds for long tasks (default 30s) |
| 2 | Removal from the request targets and stopping start at the same time | Design assuming the order is not guaranteed |
| 3 | The preStop hook runs | Wait a few seconds so the target removal can spread |
| 4 | SIGTERM arrives | Stop accepting new requests, finish in-flight ones, exit on its own |
| 5 | After the grace period, SIGKILL forces a stop | At this point, in-flight requests fail |
Set terminationGracePeriodSeconds and preStop in the pod template spec. Check the applied values with kubectl get pod <name> -o yaml.
Try it yourself
kubectl get pod <pod> -o jsonpath='{.spec.terminationGracePeriodSeconds}' # Grace period (default 30)
kubectl get pod <pod> -o jsonpath='{.spec.containers[*].lifecycle.preStop}' # preStop hook
kubectl get pods -w # Watch a deleted pod go Terminating
kubectl get endpointslices -l kubernetes.io/service-name=<service> -w # Watch it leave the targets
kubectl get events --field-selector reason=Killing # When the kubelet stopped the container
Check yourself
Further reading: Pod lifecycle — termination of Pods · Container lifecycle hooks