A StatefulSet manages Pods with stable ordinal identities and, when configured, persistent volume claims tied to those identities. Its rolling update normally proceeds one Pod at a time, waiting for readiness before continuing. A partition can hold lower ordinals at the previous template revision. That control does not make an incompatible on-disk format reversible or guarantee that application replicas can safely run mixed versions.
StatefulSet rollout safety: preserve identity and data while updating
Operational decision
A three-replica invoice index stores its shard data on separate PVCs. Back up and test the data format first, then set a rollout partition so only the highest ordinal receives the new image. Exercise reads and writes while old and new replicas coexist. The YAML fragment belongs in the StatefulSet spec and assumes three replicas; it is not a complete manifest. Check leader election, replication lag, and quorum rules before lowering the partition. If the new binary migrates disk state on startup, an image rollback might fail against that changed data. Keep a compatible reader version or restore plan. Inspect PVC retention policy before scaling down or deleting the set; a deletion setting can remove claims independently of whether the application is healthy.
spec:
replicas: 3
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 2
persistentVolumeClaimRetentionPolicy:
whenDeleted: Retain
whenScaled: RetainCost and verification
The staged replica consumes the same storage and roughly the same compute as before, but the team pays in longer rollout time and mixed-version testing. Readiness only reports the configured probe; it does not confirm shard correctness or replication safety. Measure lag and user errors while the partition is held. A retained PVC keeps data after a Pod disappears, which helps recovery but continues to incur storage cost and requires an owner for cleanup.
Common Mistakes
- Do not assume a Pod rollback reverses an on-disk migration.
- Do not lower the partition before mixed-version behavior is checked.
- Do not change PVC retention without tracing deletion consequences.
Connected lessons
- DevOps: delivery, infrastructure, and reliable operations
- Persistent storage: PVC lifecycle and data ownership
- Volume snapshots: test application-consistent restore
- Kubernetes probes: startup, readiness, and liveness
- Backups and disaster recovery: prove the restore path
