⚡ ~/naveed K8s Hub
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Phase 1 — Fundamentals Module 05 of 24 Free & Open Access

Kubernetes Storage: Volumes, PV, PVC, StorageClasses

Kubernetes storage decouples Pods from disks using Volumes, PersistentVolumes (PV), PersistentVolumeClaims (PVC) and StorageClasses. A PVC requests capacity, and a StorageClass can provision a matching PV on demand. This module covers access modes, reclaim policies and why a Pod can get stuck waiting for a volume.

Last updated: · By Naveed Ahmed, Certified Kubernetes Administrator

05 - Storage: Volumes, PV, PVC, StorageClasses

Why this matters

Stateful workloads (databases, queues, anything that can't lose data on restart) need storage that outlives the pod. This is one of the trickiest areas to get right in prod.

Read this first — Definitions & Explanations

Volume (generic)

A directory accessible to containers in a Pod. Can be ephemeral (emptyDir) or backed by real storage.

PersistentVolume (PV)

A piece of storage in the cluster provisioned by an admin or dynamically. Cluster-scoped resource representing disk/NFS/cloud volume capacity and access modes.

PersistentVolumeClaim (PVC)

A user/app request for storage (“I need 10Gi ReadWriteOnce”). The control plane binds PVC → PV.

StorageClass

Defines how dynamic volumes are created (provisioner, reclaim policy, parameters). When a PVC asks for a StorageClass, a PV can be auto-provisioned.

Access modes

Reclaim policy

What happens to a PV when PVC is deleted: Retain, Delete, or older Recycle. Know this before deleting claims in production.

Dynamic vs static provisioning

Official docs (read for detail)

Key Concepts

YouTube search terms

Hands-on lab (on prod-sim)

kubectl get storageclass    # minikube ships a default "standard" class

# Dynamic provisioning via PVC
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 1Gi
EOF
kubectl get pvc test-pvc
kubectl get pv    # see the PV that got auto-created

# Mount it in a pod, write data, delete pod, remount, prove data persists
kubectl run writer --image=busybox --restart=Never --overrides='
{"spec":{"volumes":[{"name":"data","persistentVolumeClaim":{"claimName":"test-pvc"}}],
"containers":[{"name":"writer","image":"busybox","command":["sh","-c","echo hello > /data/file.txt; sleep 3600"],
"volumeMounts":[{"name":"data","mountPath":"/data"}]}]}}'
kubectl exec writer -- cat /data/file.txt
kubectl delete pod writer --wait
kubectl run reader --image=busybox --restart=Never --overrides='
{"spec":{"volumes":[{"name":"data","persistentVolumeClaim":{"claimName":"test-pvc"}}],
"containers":[{"name":"reader","image":"busybox","command":["cat","/data/file.txt"],
"volumeMounts":[{"name":"data","mountPath":"/data"}]}]}}'
kubectl logs reader   # should print "hello" — proves data outlived the pod

# StatefulSet with per-replica storage
kubectl apply -f https://k8s.io/examples/application/web/web.yaml
kubectl get pvc -l app=nginx   # one PVC per replica: www-web-0, www-web-1, www-web-2

Common mistakes and how to avoid them

  • Having no default StorageClass, then wondering why a PVC stays Pending. Without a default class or a matching PersistentVolume, nothing provisions the volume. Check kubectl get sc and the PVC events.
  • Deleting a PVC and assuming the data is safe. With the reclaim policy Delete, removing the claim removes the volume. Use Retain for data you cannot lose.
  • Using ReadWriteOnce volumes with Pods on different nodes. ReadWriteOnce allows mounting by one node at a time, so the second Pod hangs in ContainerCreating. Use ReadWriteMany storage or schedule the Pods on the same node.
  • Using emptyDir for data that must survive. It is deleted when the Pod is removed from the node. Use a PersistentVolumeClaim for anything you need to keep.
  • Resizing a PVC without allowVolumeExpansion. Expansion is rejected unless the StorageClass allows it, and volumes can only grow. Check the class before you rely on resizing.

Quick answers

What is the difference between a PV and a PVC?

A PersistentVolume is a piece of storage in the cluster, created by an admin or provisioned dynamically. A PersistentVolumeClaim is a request for storage by a workload, stating size and access mode. Kubernetes binds each claim to a matching volume.

What does a StorageClass do?

It describes a type of storage and its provisioner, such as SSD or HDD, and lets Kubernetes create volumes on demand when a PVC references it. Without one, an admin must create PersistentVolumes by hand. The default class is used when a PVC names none.

What are the Kubernetes volume access modes?

ReadWriteOnce allows read-write mounting by a single node, ReadOnlyMany lets many nodes read, ReadWriteMany lets many nodes read and write, and ReadWriteOncePod restricts access to a single Pod. Which modes you can use depends on the storage backend.

Notes

(fill in your own words after watching + labbing)

📋 Self-Assessment Mastery Checklist (4 Competencies)
🧠 Practice Exam Questions (Module 05 MCQs)
⚡ Take Quiz & Save Progress in Tracker

Review these sample exam questions out loud, test your retrieval, and then unlock official scoring in the interactive tracker.

Question 1: A PersistentVolumeClaim (PVC) is:
  • A. A node disk partition
  • B. A request for storage by a user/Pod
  • C. A CNI plugin
  • D. An Ingress rule
✓ Correct Answer: B (A request for storage by a user/Pod)
Option B ('A request for storage by a user/Pod') is the standard production architectural best practice.
Question 2: StorageClass typically controls:
  • A. How dynamic volumes are provisioned
  • B. Pod CPU limits only
  • C. Service DNS names
  • D. RBAC roles
✓ Correct Answer: A (How dynamic volumes are provisioned)
Option A ('How dynamic volumes are provisioned') is the standard production architectural best practice.
Question 3: AccessModes like ReadWriteOnce mean:
  • A. How many Pods can mount the volume and how
  • B. Network policy rules
  • C. API rate limits
  • D. Scheduler priority
✓ Correct Answer: A (How many Pods can mount the volume and how)
Option A ('How many Pods can mount the volume and how') is the standard production architectural best practice.
Question 4: A PersistentVolume (PV) represents:
  • A. Cluster-wide storage resource
  • B. A single container filesystem layer
  • C. A ConfigMap
  • D. A Service VIP
✓ Correct Answer: A (Cluster-wide storage resource)
Option A ('Cluster-wide storage resource') is the standard production architectural best practice.
Question 5: Dynamic provisioning creates a PV when:
  • A. You create a PVC that matches a StorageClass
  • B. You restart kubelet
  • C. You apply a Service
  • D. You create a Namespace
✓ Correct Answer: A (You create a PVC that matches a StorageClass)
Option A ('You create a PVC that matches a StorageClass') is the standard production architectural best practice.
← Previous Module (04) ConfigMaps & Secrets Next Module (06) → Scheduling: Affinity, Taints, Resources, PDBs