31. How would you design persistent storage for a StatefulSet across zone failures?
A stateful workload needs one persistent volume per replica and must recover when a node or zone becomes unavailable. Design the StorageClass binding mode, access mode, volume topology, persistent volume claim templates, replica placement, snapshot and restore path, expansion, and failover procedure. Explain which recovery steps Kubernetes performs and which data replication guarantees must come from the storage system or application.
At a high level, the goal is to keep each StatefulSet replica’s data safe when a node or zone fails. The main challenge is moving a failed pod without losing access to its existing volume. I would explain the design through volume creation, replica placement, and recovery. Each pod gets its own PVC, while the CSI storage keeps data available across zones. Kubernetes reschedules pods and keeps their storage identity. The trade-off is that stronger cross-zone replication adds storage cost and write latency.
The workload must keep its data when a machine or an entire zone becomes unavailable. Each StatefulSet replica owns separate stored data. A replacement pod must therefore reconnect to that replica’s existing data instead of starting with an empty volume. Kubernetes can recreate and schedule pods, but it does not copy application data between zones. The design combines one PVC per replica, zone-aware placement, and a CSI storage system that keeps the volume available from surviving zones. It also includes snapshots, restore, volume expansion, scaling, and clear recovery responsibilities.
- Must the workload survive a complete zone failure without restoring from backup?
- Does the CSI storage replicate each volume across zones?
- What amount of data loss is acceptable during a zone failure?
- Does the CSI driver support ReadWriteOncePod and cross-zone attachment?
I would start with one persistent volume claim for each replica. The StatefulSet creates these claims from volumeClaimTemplates. In the diagram, web-0 uses data-web-0, web-1 uses data-web-1, and web-2 uses data-web-2. These PVCs are independent.
The volumeClaimTemplate should request ReadWriteOncePod when the CSI driver supports it. This means one pod can mount that claim for read and write access. RWO can be used when required by the storage driver.
The headless StatefulSet Service also keeps stable network names. For example, web-0 uses web-0.web-ss.default.svc.
The StorageClass uses volumeBindingMode: WaitForFirstConsumer. Kubernetes waits for pod scheduling before binding or provisioning the volume. This lets the scheduler consider storage topology together with node placement.
WaitForFirstConsumer does not copy data across zones. The CSI storage must separately provide volume accessibility from surviving zones.
I would spread the StatefulSet replicas across Zone A, Zone B, and Zone C. Topology spread constraints help distribute replicas across zones. Pod anti-affinity can also stop replicas from sharing the same node.
A PodDisruptionBudget protects availability during planned disruptions. These controls reduce the chance that one failure removes several replicas together.
The distributed CSI storage layer keeps copies of each volume across zones. The diagram uses synchronous replication as its example. A write reaches the required storage replicas before it is considered complete.
This durability does not come from Kubernetes. The storage system must provide cross-zone replication, volume accessibility, attach and detach behavior, snapshots, expansion, and consistent reads and writes after failover. The application must still use durable writes and recover correctly from partial failures and retries.
If Zone C fails, web-2 becomes unavailable. Kubernetes detects the failed pod or node and works toward the StatefulSet’s desired replica count. After the failed pod can be replaced, the scheduler selects a healthy node in Zone A or B only if the bound volume is accessible there.
The replacement keeps the data-web-2 PVC and its bound PV. The CSI driver attaches and publishes that same replicated volume using surviving storage replicas. The pod mounts its data, starts, and rejoins the service.
Each PVC can have a CSI snapshot. Recovery from backup creates a new PVC from a snapshot or clone. Volume expansion starts by increasing the PVC size when the StorageClass allows expansion.
Scaling up creates new PVCs for new StatefulSet replicas. Scaling down normally leaves StatefulSet PVCs in place under the shown retention behavior. If a PVC is later deleted, the StorageClass Retain reclaim policy keeps the underlying PV. The main trade-off is stronger durability versus extra storage cost and write latency.
The benefit is that a failed pod can move to another healthy zone and keep using its existing data. Cross-zone storage replication protects the volume when one zone disappears. The downside is that synchronous replication can make writes slower because data must reach several storage locations before completion. It also uses more storage. WaitForFirstConsumer improves topology-aware placement, but it does not create cross-zone durability itself. Snapshots provide another recovery path, but restoring from a snapshot is slower than attaching an already replicated volume. Keeping PVCs after scale-down protects data, but unused storage may need later cleanup.
Interviewers want to see whether you understand the boundary between Kubernetes and the storage layer. Kubernetes can manage StatefulSet identity, schedule replacement pods, and reuse existing PVCs. It does not automatically replicate the stored data across zones. A strong answer also shows judgment about storage topology, access modes, replica placement, snapshots, expansion, recovery steps, and the cost of stronger durability guarantees.










