StatefulSets Best Practices
Running stateful workloads on Kubernetes is mostly about disciplined defaults around storage, identity, and rollout.
Search across all documentation pages
Running stateful workloads on Kubernetes is mostly about disciplined defaults around storage, identity, and rollout.
This list groups the practices that keep StatefulSets safe to operate, upgrade, and scale.
Read the groups in order; each builds on the last from storage through operations.
Treat every bold item as a rule with a reason, and adapt the specifics to your database or clustered system.
Apply these before your first production StatefulSet, not after your first incident.
<template>-<statefulset>-<ordinal>, and you cannot cleanly retrofit per-pod storage later, so design it before launch.storageClassName in the template rather than relying on a cluster default that may change or differ across environments.whenScaled and whenDeleted so you neither lose data nor silently accumulate orphaned volumes and cost.allowVolumeExpansion when needed.clusterIP: None and match its name to serviceName, or pods never get stable per-member DNS.<pod>.<service>.<namespace>.svc.cluster.local for seeds and cluster membership instead of hardcoding IPs.podManagementPolicy: Parallel for shared-nothing apps.partition to update the highest ordinals first, verify, then lower it step by step.topologySpreadConstraints or anti-affinity so members land on different nodes and zones, avoiding correlated loss.initialDelaySeconds or a startupProbe so they are not killed mid-recovery.terminationGracePeriodSeconds and a preStop hook so a member leaves the cluster cleanly before the process stops.runAsNonRoot, a fixed runAsUser, and fsGroup so the pod owns its volume without root.You should have per-pod storage with an explicit class and retention policy, a headless Service for identity, and a client Service for traffic.
Your rollout should be ordered or intentionally parallel, guarded by probes, a PDB, and spread constraints.
Security should be non-root, digest-pinned, scanned, network-restricted, and running under the restricted profile.
Do I always need a headless Service?
Yes if pods must address each other by name. The StatefulSet references it through serviceName, and without it there are no per-pod DNS records.
What retention policy should I pick?
For most databases, whenScaled: Retain and whenDeleted: Retain are safest, but set whenScaled: Delete if scale-in should reclaim storage automatically.
Is a StatefulSet enough for high availability? No. It provides identity and stable storage; replication, failover, and leader election are the application's responsibility.
How do I upgrade without downtime? Use partitioned RollingUpdate to canary high ordinals, keep readiness accurate, and protect quorum with a PodDisruptionBudget.
Can I change volumeClaimTemplates later? Not the storage size retroactively for existing PVCs beyond expansion, and template changes do not apply to already-created claims. Plan storage before launch.
Should StatefulSet pods run as root?
No. Run as non-root with an explicit user and fsGroup, and hold them to the restricted Pod Security Standard.
Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Reviewed by Chris St. John·Last updated Jul 16, 2026