✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes StatefulSet Management

Kubernetes StatefulSet Management ensures reliable deployment and scaling of stateful applications with persistent storage and ordered pod creation.

Kubernetes StatefulSet Management is the operational practice of running StatefulSets safely in production, covering scaling behavior specific to ordinal identity, safe update sequencing, and the additional caution required compared to stateless workload management given the presence of persistent, per-instance state.


Scaling Considerations Unique to StatefulSets

Ordinal-Ordered Scale-Up and Scale-Down

Scaling a StatefulSet up creates new Pods at the next sequential ordinals, while scaling down removes the highest ordinals first, meaning web-0 is always the last Pod to be removed during any scale-down, an intentional design that treats lower ordinals as more foundational to the workload's identity.

kubectl scale statefulset statefulset-management-example --replicas=5

Storage Persists Through Scale-Down

Scaling down does not delete the PersistentVolumeClaims of the removed ordinals by default; they remain bound and available should the StatefulSet later be scaled back up to reclaim the same ordinal's data, a deliberate safety default that requires explicit cleanup if the storage is genuinely no longer needed.

kubectl get pvc -l app=web

Update Sequencing Discipline

Respecting the Reverse-Ordinal Order

StatefulSet management practice never attempts to bypass the built-in reverse-ordinal update ordering for workloads where instance order matters, a distributed database's primary-then-replica upgrade sequence, for instance, since the default RollingUpdate strategy's ordering exists specifically to accommodate this kind of dependency.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: statefulset-management-example
spec:
  updateStrategy:
    type: RollingUpdate

Using Partitions for Staged Validation

Management practice for high-risk StatefulSet updates uses the partition field to update and validate the highest ordinal alone before lowering the partition incrementally, treating each successful ordinal transition as confirmation before proceeding to the next.

spec:
  updateStrategy:
    rollingUpdate:
      partition: 4

Handling Node Failure Carefully

Manual Intervention for Unreachable Nodes

Because StatefulSet's at-most-one guarantee prevents automatic replacement of a Pod on an unreachable node, management practice includes a documented, deliberate procedure for verifying a node is genuinely down (not merely network-partitioned) before force-deleting the affected Pod to allow replacement.

kubectl delete pod statefulset-management-example-2 --grace-period=0 --force

The Risk of Premature Force Deletion

Force-deleting a StatefulSet Pod before confirming the underlying node is truly down risks two instances of the same ordinal identity running simultaneously if the original process is still alive on the unreachable node, a correctness violation management practice treats as a serious, deliberate risk rather than a routine recovery step.


Coordinating Application-Level Awareness

The Pod's Ordinal as Application Input

Well-managed stateful workloads expose their ordinal (typically derived from the Pod's hostname) to the application itself, letting it make identity-aware decisions, which instance is the leader, which shard of data it owns, directly from Kubernetes-provided naming rather than requiring separate external coordination.

kubectl exec statefulset-management-example-0 -- hostname

StatefulSet Management Diagram

web-0 (foundational) web-1 web-2 scale down removes right-to-left, updates apply right-to-left

Managing a StatefulSet well means consistently respecting the ordering and identity guarantees it provides, treating shortcuts around that ordering, such as bulk force-deletion during an incident, as exceptional actions requiring explicit justification rather than routine operational tools.