StatefulSet volumeClaimTemplates & Per-Pod Storage
Give each StatefulSet replica its own PVC via volumeClaimTemplates.
In plain words
volumeClaimTemplates stamp a uniquely named filing cabinet for every permanent employee number in the StatefulSet. The simple Kubernetes rule is: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
Think of it like…
volumeClaimTemplates stamp a uniquely named filing cabinet for every permanent employee number in the StatefulSet.
Where you’ve seen it
Before approving a data-path change, the storage owner runs kubectl get sts db -o yaml; kubectl get pvc -l app=db. Expected evidence: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not. If the run instead shows this symptom, stop and restore the last known state: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations.
Words you’ll hear
- volumeClaimTemplates
- For this lesson, volumeClaimTemplates is the controlling idea: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Per-Pod PVC
- Per-Pod PVC is the checkpoint; run
kubectl get sts db -o yaml; kubectl get pvc -l app=dband inspect the owner chain. Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations. - StatefulSet
- StatefulSet is the outcome to preserve; the cost is explicit: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.
- Verification evidence
- The evidence command is
kubectl get sts db -o yaml; kubectl get pvc -l app=db. It connects the declaration to this behavior: Give each StatefulSet replica its own PVC via volumeClaimTemplates.
Visual diagram
Theory & deep dive
How volumeClaimTemplates reaches the intended state
Give each StatefulSet replica its own PVC via volumeClaimTemplates. A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
The concrete checkpoint is kubectl get sts db -o yaml; kubectl get pvc -l app=db; compare the volumeClaimTemplates owner, Per-Pod PVC state, and StatefulSet outcome instead of treating YAML acceptance as proof.
Run kubectl get sts db -o yaml; kubectl get pvc -l app=db after the change and correlate the result with Events and the owning object. A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
Per-Pod PVC: failure boundary and production cost
Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations. The prerequisite contract is concrete: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks. A safe design limits blast radius, records the last good configuration, and uses kubectl get sts db -o yaml; kubectl get pvc -l app=db as a deterministic rollback checkpoint.
Capture the current state with kubectl get sts db -o yaml; kubectl get pvc -l app=db, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations.
How it works, step by step
Step 1 of 41. Declare the data contract
State capacity, topology, access, and ownership in the claim or class: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Goal
- Give each StatefulSet replica its own PVC via volumeClaimTemplates.
- Owner
- volumeClaimTemplates
When to use it & trade-offs
What it is
Give each StatefulSet replica its own PVC via volumeClaimTemplates. A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
Why it matters: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations. The invariant at risk is specific: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not. The quickest fact check before changing the design is kubectl get sts db -o yaml; kubectl get pvc -l app=db.
When to reach for it
- Use volumeClaimTemplates to enforce this invariant: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Use Per-Pod PVC evidence from
kubectl get sts db -o yaml; kubectl get pvc -l app=dbin reviews and incident timelines. Give each StatefulSet replica its own PVC via volumeClaimTemplates. - Choose the managed external data plane route only when this cost is justified by governance or scale: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.
When to avoid or be careful
- Avoid assuming volumeClaimTemplates is complete after YAML submission; the required behavior is concrete: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get sts db -o yaml; kubectl get pvc -l app=dbfirst: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations. - Avoid adopting a heavier platform wrapper before measuring its cost: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.
Native, manual, and managed paths for volumeClaimTemplates
kubectl get sts db -o yaml; kubectl get pvc -l app=db.Strengths: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
Watch out: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks. Recovery must also recognize this signal: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations.
kubectl get sts db -o yaml; kubectl get pvc -l app=db; the expected invariant is: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.Strengths: kubectl get sts db -o yaml; kubectl get pvc -l app=db gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike volumeClaimTemplates, it does not make this symptom self-documenting: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations.
kubectl get sts db -o yaml; kubectl get pvc -l app=db.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
Watch out: The added platform ownership buys value at this cost: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Trace volumeClaimTemplates to StatefulSet through Per-Pod PVC; the invariant is: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Recognize the symptom: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations.
- Justify the cost: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.
- Verify with kubectl get sts db -o yaml; kubectl get pvc -l app=db instead of only inspecting YAML.
Benchmarks & rules of thumb
- 0
- first PVC ordinal
- 1
- claim is created for each StatefulSet replica template
- 2
- separate owner concepts: Pod identity and retained PVC identity
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the volumeClaimTemplates owner contract: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not.
- Ignoring this telltale condition leads to unrelated changes: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations.
- Repeating
kubectl get sts db -o yaml; kubectl get pvc -l app=dbwithout an owner for remediation wastes retry cost. Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not?
- Which owner object, logs, and Events would you inspect for this symptom-Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations-?
- At what threshold would this cost become unacceptable: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks?
kubectl get sts db -o yaml; kubectl get pvc -l app=db, name the failure, then justify the cost. Invariant: A StatefulSet volumeClaimTemplates creates one PVC per Pod ordinal, so db-0 keeps db-data-db-0 across replacement while the ReplicaSet-style shared template model would not. Failure: Scaling a StatefulSet down and deleting its Pods does not normally delete PVCs, so a later ordinal can reconnect stale data and a longer retention policy changes cleanup expectations. Cost: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.Knowledge check
Put it into practice
Practice related interview Q&A
Apply StatefulSet volumeClaimTemplates & Per-Pod Storage with generative AI interview Q&A and hands-on practice.