QA
Intermediate LevelDocker & Deployment

How do PersistentVolumes (PV) and PersistentVolumeClaims (PVC) manage stateful storage?

❓ Interview Prompt: Explain the PV/PVC abstraction layer, dynamic provisioning via StorageClasses, and access modes for stateful Kubernetes workloads.

Kubernetes decouples storage provisioning (how storage is created) from storage consumption (how Pods request storage) through PV/PVC:

PersistentVolume (PV) — The Storage Resource:

A PV is a piece of physical storage in the cluster — provisioned by an admin or dynamically by a storage driver (CSI plugin). PVs exist independently of any Pod.

PersistentVolumeClaim (PVC) — The Storage Request:

A PVC is a storage request from a Pod — specifying required size, access mode, and StorageClass. Kubernetes matches PVCs to PVs (binding).

Access Modes:

•
ReadWriteOnce (RWO): Mounted read-write by ONE node (block storage: EBS, GCP PD).
•
ReadOnlyMany (ROX): Mounted read-only by MANY nodes.
•
ReadWriteMany (RWX): Mounted read-write by MANY nodes (NFS, EFS, CephFS).

Dynamic Provisioning (StorageClass):

Instead of pre-creating PVs, a StorageClass defines a provisioner (e.g., ebs.csi.aws.com) that automatically creates PVs when PVCs are submitted.

Reclaim Policy:

•
Retain: PV data preserved after PVC deletion — manual cleanup required.
•
Delete: PV (and underlying cloud volume) deleted when PVC is deleted.

Code Implementation Example

yaml
# StorageClass — dynamically provision AWS EBS volumes
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ssd
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  iops: "3000"
reclaimPolicy: Retain         # keep data after PVC deletion
volumeBindingMode: WaitForFirstConsumer  # provision in Pod's AZ
---
# PersistentVolumeClaim — request 20GB fast-ssd storage
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce      # single node RW (EBS is block storage)
  storageClassName: fast-ssd
  resources:
    requests:
      storage: 20Gi
---
# Pod using the PVC
spec:
  containers:
    - name: postgres
      image: postgres:16-alpine
      volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: pgdata
  volumes:
    - name: pgdata
      persistentVolumeClaim:
        claimName: postgres-pvc
💡StorageClass dynamically provisions an EBS gp3 volume; PVC claims 20GB; Pod mounts it via volumeClaim.
🎯 Interview Key Takeaway

PVCs are storage requests; PVs are storage resources. Use StorageClasses with dynamic provisioning to avoid manual PV management. Set reclaimPolicy: Retain for production databases.

#Kubernetes#PersistentVolume#PVC#StorageClass#Stateful Storage#Intermediate
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?