Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 70/ 160
04. Storage & Persistent Data

StatefulSet volumeClaimTemplates & Per-Pod Storage

Give each StatefulSet replica its own PVC via volumeClaimTemplates.

IntermediatevolumeClaimTemplates · Per-Pod PVC · StatefulSet3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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=db and 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

Loading interactive 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.

Verify Per-Pod PVC, not only object creation

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.

Key takeaway: volumeClaimTemplates is implemented only when this invariant remains observable: 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.

Recover from Per-Pod PVC drift

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.

Key takeaway: Accept the trade-off consciously: Per-replica claims preserve identity and recovery, but accumulation, capacity expansion, and restoring a quorum each require ordinal-aware runbooks.

How it works, step by step

Step 1 of 4
Data owner

1. 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.

volumeClaimTemplates contract → owned state
Key numbers at this step
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=db in 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=db first: 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

Dynamically provisioned storage
Best for: Give each StatefulSet replica its own PVC via volumeClaimTemplates. A concrete incident check is 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.

Manual pre-provisioning
Best for: Quickly testing the Per-Pod PVC assumption with 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.

Managed external data plane
Best for: Teams that need StatefulSet integrated with guardrails; the evidence path is 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=db without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Distributed & Self-Hosted Storage (Rook-Ceph, Longhorn, OpenEBS)
Next topic
Volume Expansion & Resizing PVCs Online