Pro ยท Lesson 6 of 12

Storage and StatefulSets

A Pod's disk disappears with the Pod unless you asked for a volume that outlives it. A StatefulSet is for pods that need stable names.

Sign in to save your place.

Picture it this way

emptyDir is a backpack the boat throws away when it sinks. A PersistentVolumeClaim is a locker with a number. A StatefulSet gives each boat the same name and the same locker when it is rebuilt.

Volumes that die and volumes that do not

emptyDir lasts for the life of the Pod. It is fine for a cache. hostPath mounts the node's disk. It pins you to that node and is a sharp tool on a shared cluster. A PersistentVolumeClaim asks a StorageClass for a volume. The CSI driver, not Kubernetes itself, talks to the disk system.

ReadWriteOnce, ReadWriteMany, and the newer access modes depend on the driver. A claim the driver cannot satisfy stays Pending. That is a storage problem, not a YAML typo, once the class name is right.

Volume Survives a new Pod? Typical use
emptyDir No Scratch space
hostPath Only on that same node Avoid on multi-tenant clusters
PVC Yes, if the reclaim policy keeps it Databases and queues

StatefulSet identity

A StatefulSet gives Pods stable names: db-0, db-1. It creates volumes from volumeClaimTemplates so each ordinal can keep its own disk. Startup and rolling replacement are ordered unless you change the policy.

A StatefulSet does not make a database highly available by itself. Replication, failover, and backups are the database's job. The workload object only gives you stable identity and disks.

What happens when the Pod is replaced

  1. Pod
  2. emptyDir
  3. Gone

Step 1 of 3The scratch disk is deleted with the Pod.

Lab: watch emptyDir disappear

Write a file in a Pod, delete the Pod, and start another with the same image. The file should be gone. Do not use hostPath for this lab.

kubectl run scratch --image=busybox:1.36 --restart=Never --command -- sh -c 'echo hello > /tmp/note && sleep 3600'
kubectl exec scratch -- cat /tmp/note
kubectl delete pod scratch --wait=false
# a new Pod with the same image will not have /tmp/note

Concept summary

Knowledge check

You stored a file in emptyDir and replaced the Pod. Where is the file?

What does a StatefulSet add that a Deployment does not?

A PVC stays Pending. What is a reasonable first check?

Official sources

Checked against the linked documentation in October 2026. A later release can move a flag, a price, or a supported pair. Use the page for the version you installed.