Identity-Linked Storage
Identity-Linked Storage
StatefulSet members need disks that survive rescheduling: mysql-0 must find its data wherever it lands next. volumeClaimTemplates deliver this by generating one PVC per ordinal:
volumeClaimTemplates:
- metadata: { name: data }
spec:
accessModes: [ReadWriteOnce]
storageClassName: fast-ssd
resources: { requests: { storage: 50Gi } }
The generated claims follow data-<pod-name> — data-mysql-0, data-mysql-1 — and are never deleted with the set by default. On reschedule, kubelet reuses the ordinal's existing claim: identity binds storage, so the disk follows the member rather than the node.
Scaling out creates the next claim alongside the next pod; scaling in keeps data for a possible scale-back.
Quorum-Safe Patterns
Quorum-Safe Patterns
Clustered stores need coordination beyond disks:
- Ordered updates plus a PDB — restart one member at a time; a PodDisruptionBudget of
minAvailable: 2on a three-member set stops drains from taking quorum. - Honest readiness — a member that joined but cannot vote must fail readiness, or the controller rolls through the fleet too fast.
- DNS-based formation — first pod bootstraps, later pods join via headless names like
mysql-0.mysql.
# companion PodDisruptionBudget
minAvailable: 2
Write-ahead logs or index data can live in a second claim template (wal-<pod>), giving two volumes under one identity. Use podManagementPolicy: Parallel for faster initial creation while keeping ordered updates.
Pitfalls and Interview Angles
Pitfalls and Interview Angles
Pitfall 1 — careless delete and recreate. PVCs outlive the StatefulSet by design; recreating with the same name reattaches old volumes with old data, schema migrations included. Know your cleanup procedure before deploying.
Pitfall 2 — stuck volume attachments after node loss. An RWO volume attached to a dead node must detach before the pod can start elsewhere; multi-attach errors in describe mean the CSI driver's detach has not completed.
Interview-ready: explain how volumeClaimTemplates link identity to storage, walk a safe scale-out and scale-in, and describe quorum protection as the trio of PodDisruptionBudget, truthful readiness gates, and ordered updates.
Quiz
1. What naming pattern do PVCs from volumeClaimTemplates use?
2. Why pair a StatefulSet with a PodDisruptionBudget?
3. Are PVCs deleted when you delete the StatefulSet?
Flashcards
Question
volumeClaimTemplates
Click to reveal answer
Answer
Generates one PVC per ordinal (data-mysql-0…), retained and reattached on reschedule.
Question
Quorum protection trio
Click to reveal answer
Answer
PodDisruptionBudget + readiness gates that reflect cluster health + ordered updates.
Question
Parallel podManagementPolicy
Click to reveal answer
Answer
Creates/starts pods without ordinal waiting — faster bootstrap, use with care on clustered stores.
Question
Multi-attach errors
Click to reveal answer
Answer
RWO volume still attached to a previous node; CSI detach or node cleanup is pending.
Revision Notes
Key Takeaways
- 1. Claim templates tie storage to ordinal identity, not to nodes
- 2. Data survives set deletion — recreate deliberately
- 3. Quorum safety needs PDBs and honest readiness, not just ordered pods
Interview Tips
- • Describe a safe 3-member rolling upgrade with concrete fields
- • Explain what happens on delete-then-recreate of a StatefulSet and why
Cheat Sheet
volumeClaimTemplates → data-