Every rollout, every scale-down, every node drain and every cluster upgrade stops pods that were working fine. If each of those stops drops a handful of requests, your service returns errors during routine operations, and nobody is paged for it because nothing is broken.
Two causes stand out. The application doesn't handle SIGTERM, or it handles it too well and exits before the rest of the cluster has stopped sending it traffic.
Who this is for: engineers whose services return a few 502s or connection resets on every deploy, and anyone setting terminationGracePeriodSeconds by guesswork.
What you walk away with: the termination sequence as Kubernetes documents it, the race that drops requests and how to close it, a way to size the grace period, and the settings that decide what happens when a node goes away.
Everything below comes from the Kubernetes v1.37 documentation and source code. The pod-level behaviour was checked on one cluster (GKE 1.36.4 with Dataplane V2, 17 November 2026); node shutdown, drains and external load balancers were not.
The mistakes, and what they cause
The process never receives SIGTERM. The image starts the application through a shell, the shell is PID 1, and it doesn't pass the signal on. The application carries on serving until the grace period runs out and is then killed mid-request. Every termination takes the full grace period, which slows rollouts and drains.
The process exits the moment it receives SIGTERM. This looks correct and still drops requests: other components keep routing traffic to the pod for a short time, and those requests meet a closed port.
The grace period doesn't cover the work. A preStop hook of 30 seconds with the default 30-second grace period leaves the application about two seconds between SIGTERM and SIGKILL.
Long-lived connections are ignored. Removing a pod from a Service stops new connections only. Keep-alive connections, WebSockets and gRPC streams keep going to the old pod until someone closes them.
Workers abandon their job. A queue consumer killed mid-message loses the message or processes it twice, depending on how it acknowledges.
The termination sequence
When a pod is deleted, by you, by a controller or through the eviction API, the documented flow is:
- The API server records the deletion. The pod gets a deletion timestamp and a grace period, and shows as
Terminating. The grace period countdown starts now. - Two things then happen at the same time, on different machines:
- On the node, the kubelet sees the pod is terminating and begins local shutdown.
- In the control plane, the pod is taken out of service. Its endpoint in the EndpointSlices gets
terminating: trueandready: false, whileservingkeeps following the readiness probe. ReplicaSets stop counting it as a replica, so a replacement is created straight away.
- The kubelet runs the
preStophook, if the container defines one and the grace period isn't zero. The hook must finish before the signal is sent. - The kubelet has the runtime send the stop signal to PID 1 of each container. That is SIGTERM unless the image sets a
STOPSIGNALand the runtime honours it. Without sidecars, containers get the signal in arbitrary order. - When the grace period expires, any process still running gets SIGKILL.
- The kubelet removes the pod object from the API server.
Two details to keep in mind:
- The grace period includes the hook. The countdown begins at step 1, before the
preStophook runs. If the hook is still running when the grace period expires, the kubelet grants a one-off extension of 2 seconds. - SIGKILL can't be handled. Whatever your process was doing at that point is lost.
The race
Step 2 is where requests are lost. Updating the EndpointSlice is one API write, but acting on it takes longer. Every kube-proxy, or its replacement, has to see the change and reprogramme its node. Ingress controllers and gateways have to update their upstreams. External load balancers have to deregister the target. None of them reports back to the kubelet.
Meanwhile the kubelet has already started shutting the pod down. If the application closes its listener as soon as SIGTERM arrives, some part of the network still sends it new connections, and those fail.
The pod has to bridge the gap itself: accept traffic for a few seconds after termination begins, then drain.
Closing the gap with a preStop sleep
The fix is a preStop hook that does nothing but wait. Because SIGTERM is only sent once the hook finishes, the application keeps serving normally while the routing change spreads.
An exec hook that runs sleep fails on images without that binary. The native sleep action, stable since v1.34, is performed by the kubelet itself:
spec:
terminationGracePeriodSeconds: 45
containers:
- name: app
image: registry.example.com/app:1.4.2
lifecycle:
preStop:
sleep:
seconds: 10
How long to sleep depends on what sits in front of the pod. Kubernetes doesn't publish a figure for how long endpoint changes take to reach every node. Five to fifteen seconds is the conventional range for in-cluster traffic; no primary source gives a value. On the test cluster (Dataplane V2, ClusterIP only) a deleted pod got its last new connection within a second; rolling restarts failed about 25 of 4,800 requests without the hook and none with a one-second sleep. If an external load balancer sends traffic straight to pod IPs, the sleep has to cover its deregistration time, a number to take from your provider's documentation.
The trade-off is that every termination, and so every rollout, takes that much longer. The hook also runs when the kubelet stops a container for a failed liveness probe, so the sleep delays those restarts and counts against a probe-level grace period.
Hook delivery is "at least once", so a hook that does more than sleep has to tolerate running twice.
What the application has to do on SIGTERM
The sleep only postpones the signal. Once SIGTERM arrives, the process should:
- Stop accepting new connections, or stop taking new work.
- Finish in-flight requests, with an upper bound shorter than the time left.
- Close idle keep-alive connections, so clients reconnect and land on another pod.
- Release what it holds: flush buffers, close database connections, give up leases.
- Exit with status 0.
If your HTTP framework ships a graceful shutdown function for the first three, it still has to be wired to the signal.
You don't need to fail the readiness probe to get a terminating pod out of the Service: deletion sets the endpoint's ready condition to false whatever the probe says. Failing it early can work against you. The EndpointSlice documentation says proxies may still route to endpoints that are both serving and terminating when every available endpoint is terminating, and a failed readiness probe turns serving off. Health probes done right has the detail.
PID 1 and signals that never arrive
The signal goes to process 1 in the container. Whether your application is process 1 depends on how the image starts it.
# Shell form: PID 1 is /bin/sh, your app is its child
ENTRYPOINT ./server --port 8080
# Exec form: your app is PID 1
ENTRYPOINT ["./server", "--port", "8080"]
The Dockerfile reference says of the shell form that the command is started as a subcommand of /bin/sh -c, "which does not pass signals", so the executable "will not receive Unix signals". Not every shell stays: in the test Alpine's busybox sh -c replaced itself with the command, Debian's sh didn't. The same applies to a wrapper script that launches the application as a child. End such a script with exec, so the application replaces the shell:
#!/bin/sh
set -e
./migrate-config
exec ./server --port 8080
Check what is running as PID 1:
kubectl exec <pod> -c app -- cat /proc/1/cmdline | tr '\0' ' '
Being PID 1 has its own catch. The Linux pid_namespaces(7) manual page says a signal reaches a namespace's init process only if that process "has established a handler for that signal", SIGKILL and SIGSTOP excepted. Docker's docker run reference puts it this way: PID 1 "doesn't terminate on SIGINT or SIGTERM unless it's coded to do so". So an application that is PID 1 and has no SIGTERM handler runs until SIGKILL. A small init such as tini runs as PID 1, forwards signals to your process and reaps zombie processes, which helps when the application spawns children or you can't add a handler to it. It doesn't replace handling SIGTERM in the application. With shareProcessNamespace: true, the documentation notes that the container process no longer has PID 1 at all.
If your process shuts down gracefully on a different signal, set STOPSIGNAL in the image. The lifecycle.stopSignal field is still alpha and off by default in v1.37 (ContainerStopSignals), and it requires spec.os.name on the pod.
Sizing the grace period
terminationGracePeriodSeconds is a pod-level field with a default of 30 seconds. It has to cover everything from deletion to exit:
terminationGracePeriodSeconds ≥ preStop duration + longest drain + margin
A long grace period has costs. A node drain waits for it, a pod that hangs during shutdown holds its resources for the whole period, and a liveness-probe restart uses it too unless you set a shorter probe-level value.
The pod's value can be overridden per deletion. kubectl delete pod --grace-period=<seconds> replaces it, and --now means one second. --grace-period=0 --force is different in kind: the API server removes the pod object without waiting for the kubelet to confirm, and the documentation warns that the processes "may continue to run on the cluster indefinitely".
Long-lived connections
The server has to end long-lived connections itself:
- HTTP/1.1 keep-alive: after SIGTERM, answer in-flight requests with
Connection: closeand close idle connections. - HTTP/2 and gRPC: send GOAWAY, which lets the server stop accepting new streams while it finishes the open ones. grpc-go's
GracefulStopdoes this and then blocks until pending RPCs finish, so give it a deadline and fall back toStop. - WebSockets and other sessions: send a Close frame (RFC 6455 has status 1001, "going away", for a server going down), then close after a deadline.
Clients have to reconnect and retry idempotent requests.
Jobs and queue workers
Workers have no inbound traffic, so there is no endpoint race and a preStop sleep adds nothing.
On SIGTERM a worker should stop taking new messages, then either finish the current one within the grace period or hand it back to the queue. Acknowledge a message only after the work is done, so that a kill results in redelivery. A message can then be processed twice, so the handler must be idempotent.
For Job pods, every pod failure counts towards backoffLimit, which defaults to 6, and without a pod failure policy (or podReplacementPolicy: Failed) the Job controller counts a terminating pod as failed at once, even if it later exits 0. A podFailurePolicy rule with the Ignore action on the DisruptionTarget condition keeps drains, preemption and other disruptions out of that count. The policy requires restartPolicy: Never, and with it the controller judges and replaces a pod only once it has reached the Failed phase.
Jobs longer than any grace period you are willing to set need checkpointing; graceful shutdown can't save them.
Sidecars on termination
If a proxy sidecar exits before the application, the application can't finish its in-flight requests.
Native sidecars (init containers with restartPolicy: Always, stable since v1.33) solve this. The kubelet delays SIGTERM to sidecars until the last main container has fully terminated, then stops them in reverse order of their definition. preStop hooks used only to order shutdown can then be removed.
The shared grace period is the catch. If the main container uses all of it, the sidecars get SIGTERM and, two seconds later, SIGKILL. The documentation says non-zero exit codes from sidecars at pod termination are normal and should be ignored by tooling. If a sidecar must flush something, leave it room in the grace period.
When the node goes away
Drains. kubectl drain uses the eviction API, which respects PodDisruptionBudgets and gives each pod its normal termination sequence with its full grace period. Upgrading without downtime depends on it.
Node shutdown without a drain. The kubelet has a graceful node shutdown feature: it detects a system shutdown through systemd inhibitor locks and terminates pods through the normal process before the node powers off. The feature gate has been on by default since v1.21, but that doesn't mean it is active. Both of its settings default to zero, and the documentation says the feature isn't activated until both are non-zero:
# KubeletConfiguration
shutdownGracePeriod: 30s # total delay of the node shutdown
shutdownGracePeriodCriticalPods: 10s # reserved for critical pods
With these values, ordinary pods get 20 seconds and critical pods the last 10. This is a per-node budget, so a pod with terminationGracePeriodSeconds: 120 on such a node gets 20 seconds when the node shuts down. shutdownGracePeriodByPodPriority sets it per priority class instead. Whether a managed platform sets any of this differs by provider, so check yours.
Spot and preemptible nodes. The provider gives short notice before reclaiming the machine, and the length is theirs to set. Something has to turn that notice into a drain, such as a node termination handler or the node autoscaler. Check that one is installed and that your grace periods fit inside the notice.
Hard failure. A node that loses power runs no shutdown sequence. StatefulSet pods then stick in Terminating, with their volumes attached, until the node returns or someone confirms it is off and adds the node.kubernetes.io/out-of-service taint. Nothing else in this article helps; the mitigations are replicas spread across nodes and zones (see topology spread vs anti-affinity) and clients that retry.
Checking what you run
# Grace period and preStop per container
kubectl get pods -n <namespace> -o json | jq -r '
.items[] | .metadata.name as $p | .spec.terminationGracePeriodSeconds as $g
| .spec.containers[]
| "\($p)/\(.name) grace=\($g)s preStop=\(.lifecycle.preStop // "none" | tostring)"'
# Watch an endpoint change state while its pod terminates
kubectl get endpointslices -l kubernetes.io/service-name=<service> -o yaml -w
Three signs of a shutdown problem:
- Pods sit in
Terminatingfor exactly the grace period. The process isn't exiting on SIGTERM. Check PID 1. - Containers end with exit code 137 after a deletion. That is 128 + 9: they were killed with SIGKILL.
- Errors at the proxy or load balancer cluster around deploys and scale-downs. That is the race, or connections that were never drained.
Checklist
- The application is PID 1 (exec form, or
execin the wrapper), or runs under an init that forwards signals. - It handles SIGTERM: stops accepting, finishes in-flight work, closes idle connections, exits 0.
- Services that receive traffic have a
preStopsleep long enough for routing to catch up. - The grace period covers the sleep plus the drain, with margin.
- Long-lived connections are closed by the server during the drain.
- Workers acknowledge after the work, and their handlers are idempotent.
- Proxies are native sidecars, so they outlive the application container.
- You know what a node shutdown gives your pods, on ordinary and on spot capacity.