Skip to main content

Moving a StatefulSet to Spot Nodes Leaves Reclaimed Pods Terminating and Their Volumes Attached

High severityKubernetes About 20 minutes to fix

Overview

A reclaimed spot node leaves a StatefulSet Pod stuck Terminating and its volume attached. The documented recovery avoids a force delete.

At a glance

Symptom
A database or queue that ran happily on on-demand nodes was moved to a spot node group as a cost saving.
Likely cause
The Kubernetes documentation on non-graceful node shutdown describes exactly this case.
Impact
The stateful workload is down until a human acts, and the pressure to act quickly is the real hazard.
Verification signal
The Pod's name is held by a new Pod on a different node, in Running and Ready.
Safe correction
The supported route is the out-of-service taint.
Rollback or recovery
The taint is the only state change, and removing it is the rollback: kubectl taint nodes node.kubernetes.io/out-of-service:NoExecute-.

A StatefulSet moved onto spot nodes can come back from its first reclaim with its Pod stuck in Terminating on a node that no longer exists, and the replacement Pod waiting for a volume that is still attached to that node.

The Pod cannot be recreated until the kubelet confirms the old one is gone, and a dead kubelet cannot confirm anything. The documented fix is to check the node really is down, mark it with the node.kubernetes.io/out-of-service taint, and remove the taint once the Pods have moved.

The tempting shortcut, kubectl delete pod --grace-period=0 --force, frees the Pod name without proving anything about the old Pod. For a Pod holding a read-write volume that is a bet on the machine being gone.

Symptom

A database or queue that ran happily on on-demand nodes was moved to a spot node group as a cost saving. The first time the provider takes a node back, kubectl get nodes shows it NotReady and the Pod that ran there sits in Terminating indefinitely. A node that vanished without the kubelet noticing looks like this:

NAME           STATUS     ROLES    AGE   VERSION
spot-node-a    NotReady   <none>   12d   (version)

NAME      READY   STATUS        RESTARTS   AGE
db-0      1/1     Terminating   0          3d

Nothing is started in its place. The StatefulSet controller will not create a second db-0 while the first still exists in the API, so the service stays down until someone intervenes.

Why it looks safe when a reclaim feels like a drain

Reclaiming a node feels like a drain, and a drain works: Pods are evicted and move. That assumption holds only when the kubelet is alive to run the shutdown. Graceful node shutdown is off by default, because shutdownGracePeriod and shutdownGracePeriodCriticalPods both default to zero, and the feature depends on systemd inhibitor locks, so a machine that is removed without those locks never gives the kubelet its chance.

Root cause

The Kubernetes documentation on non-graceful node shutdown describes exactly this case.

When a node is shut down and the kubelet’s Node Shutdown Manager does not detect it, the StatefulSet Pods on it stay in Terminating, because the kubelet that would delete them is not available, so the StatefulSet cannot create a Pod with the same name. The VolumeAttachments are not deleted from the shutdown node either, so the volumes cannot attach to a new node.

That second half is the part that surprises people. The access mode on the volume is the reason it matters: ReadWriteOnce means the volume can be mounted read-write by a single node, so the new Pod cannot have it until the old attachment is released. If the original node comes back, its kubelet deletes the Pods and new ones start elsewhere. If it never does, the Pods stay in Terminating forever.

Impact

The stateful workload is down until a human acts, and the pressure to act quickly is the real hazard.

Kubernetes also force-detaches volumes for a Pod whose deletion has not succeeded for 6 minutes when the node is unhealthy at that moment. The documentation warns that any workload still running on the node and using a force-detached volume violates the CSI specification and risks data corruption. A node that is only unreachable, not gone, is the dangerous case: it may still be writing.

How to confirm it is this problem

Three read-only checks establish the diagnosis. First, find the node and its conditions. Second, find the Pod and the node it is bound to. Third, look for a VolumeAttachment that still names the dead node. Check the machine itself in your provider’s console before anything else: the next section depends on knowing it is shut down or powered off, not rebooting.

  • kubectl get nodes and kubectl describe node <node> show the NotReady condition and any taints already on it.
  • kubectl get pods -n <namespace> -o wide shows the Pod in Terminating and the node it is bound to.
  • kubectl get volumeattachments lists attachments cluster-wide; one whose node column names the dead node is the volume the new Pod is waiting for.

The shortcut that costs more than the outage

Under pressure people run kubectl delete pod db-0 --grace-period=0 --force.

The StatefulSet documentation is blunt: a force deletion does not wait for the kubelet to confirm the Pod has stopped, and it immediately frees the name so a replacement can be created. If the old Pod is in fact still running and can reach its peers, you now have two members with one identity, which the documentation says can be disastrous and may lead to data loss, with split brain as its example.

A forced delete also does not itself detach the volume; in the documented procedure, the detach is a separate step. When you force delete, you are asserting that the Pod will never make contact again. Make that assertion by checking the machine, not by hope.

Correction

The supported route is the out-of-service taint. Before applying it, verify that the node is in shutdown or power-off state, not in the middle of restarting. Then taint it with the NoExecute or NoSchedule effect. Pods without a matching toleration are forcibly deleted and volume detach happens immediately, so the replacement can start on a healthy node.

  1. Confirm in the provider console that the machine is stopped or terminated.
  2. Note which Pods and VolumeAttachments reference the node, so you can prove afterwards that they moved.
  3. Apply kubectl taint nodes <node> node.kubernetes.io/out-of-service=nodeshutdown:NoExecute. The value is optional in the taint syntax; the key and effect are what the documentation specifies.
  4. Watch the Pod reschedule and the volume attach to its new node.
  5. Remove the taint yourself once the Pods have moved and you have checked the node has recovered or been removed. The documentation says you must, since you added it.

Following along? Tap a step’s number to tick it off.

If the machine is permanently gone, the StatefulSet documentation also lists deleting the Node object as a recommended way to free its Pods. Either way, the new Pod starts on a different node and may need to pull its image and recover from an unclean stop: see Kubernetes ImagePullBackOff and Kubernetes CrashLoopBackOff if the replacement does not reach Ready.

Validation

The Pod’s name is held by a new Pod on a different node, in Running and Ready. The VolumeAttachment that named the old node is gone and one naming the new node exists. The old node no longer lists the Pod. If the volume mounts but the application cannot write, the ownership problem is separate: fsGroup permissions on hostPath volumes covers one way that happens.

Rollback

The taint is the only state change, and removing it is the rollback: kubectl taint nodes <node> node.kubernetes.io/out-of-service:NoExecute-. Remove it once the Pods have moved, not before. Pods that were already deleted do not come back, and removing the taint does not undo the detach, so the precondition matters more than the rollback. If the node turned out to be restarting rather than down, stop, remove the taint, and let its kubelet reconcile the Pods.

How to stop it happening on the next reclaim

Before the next node group change, decide who takes the decision. Configure shutdownGracePeriod and shutdownGracePeriodCriticalPods to non-zero values on spot nodes, so a kubelet that is given warning can terminate Pods and release volumes itself; both default to zero, which leaves graceful shutdown off. Note that the feature depends on systemd, and that the Debian unattended-upgrades package conflicts with it in its default configuration when shutdownGracePeriod is above 30 seconds.

Keep single-writer stateful workloads on on-demand nodes unless you have rehearsed the recovery above, and write the out-of-service procedure into the on-call runbook with its precondition. Consider disabling force detach on timeout with disable-force-detach-on-timeout in the kube-controller-manager only if you accept that unhealthy attached volumes then need the non-graceful procedure to recover.

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

Terminating
node.kubernetes.io/out-of-service
kubectl delete pod --grace-period=0 --force
4

When to escalate

Validation and rollback are covered in the sections above.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Found this useful? Follow KBY for more like it.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.

Discover more

Connected KBY resources