Volumes and persistent claims
Decide which files should survive a container restart, Pod replacement, or storage release.
What you will understand
- Match container files, emptyDir, and claims to the lifetime the application needs.
- Trace a mount from its container directory to a bound PersistentVolume.
- Predict the effects of access modes and reclaim policy before changing a workload.
Builds on: Ingress, Gateway API, and TLS
Which files survive a restart or replacement
A report generator writes a scratch file and a finished report. The scratch file belongs to the current run. The report should still exist if Kubernetes replaces the Pod. Start by picking the lifetime each file needs. A container’s writable image layer can be lost when the container is recreated. An emptyDir volume starts with a Pod and is available through container restarts within that Pod. When the Pod goes away, its emptyDir goes with it.
A PersistentVolumeClaim (PVC) is a request for storage in a namespace. A PersistentVolume (PV) represents a specific piece of storage the cluster can provide. A claim binds to a volume that satisfies requirements such as capacity, storage class, and access mode. The Pod refers to the claim by name and mounts the storage in a container. Work through the first scene with both a container restart and a Pod replacement.
Which files survive a restart or replacement?
Compare a container’s writable layer, a Pod-scoped emptyDir, and a persistent volume mounted through a claim.
Write one marker to each mount
- ContainerWritable layer/tmp/local
- ContaineremptyDir/scratch
- ContainerPVC app-data/data
- PVC app-dataPV databound
The same process can write to its own filesystem, a Pod-scoped emptyDir and a claim-backed mounted path.
Restart the container
- Writable layerFresh for a restarted container
- PV dataUnderlying storage lifecycle
- ContaineremptyDirsame Pod volume
- ContainerPVC app-dataremount claim
A new container filesystem starts from the image. The Pod is the same, so its emptyDir and PVC mounts remain available.
Replace the Pod
- Writable layerFresh for a restarted container
- emptyDirBelongs to this Pod
- PV dataUnderlying storage lifecycle
- ContainerPVC app-datasame claim name
A replacement has a new Pod identity and new emptyDir. It can refer to the same PVC to recover persistent data.
Read data from the bound volume
- PVC app-dataPV datainspect PV + driver
Claim-backed persistence depends on the real storage provider and policy; a local node directory does not imply cross-node durability.
Storage implementation remains available; the scene does not claim backup or node-loss recovery.
Try the mechanism with your own inputs
- PVC to PV volume-abind
Capacity, storage class, and availability match. Actual binding also considers access modes, topology, volume mode, and provisioning policy.
spec:
storageClassName: fast
resources:
requests:
storage: 1GiInspect YAML or commands
Inspect the backing resource
kubectl describe pvc app-data
kubectl get pvExplore another case
Connect a claim to a container directory
The example asks for a 1 GiB volume. The first document is a complete PVC. The second is a fragment for a Pod’s spec. The Pod-level volume named data refers to claim app-data. The container-level mount exposes that volume at /data. The writer appends a line every time the container starts, which makes it easy to see whether a later Pod found the old file.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 1Gi
---
# Fragment: a Pod spec mounting the claim in one container.
containers:
- name: writer
image: busybox:1.36
command: ["sh", "-c", "echo marker >> /data/visits; sleep 3600"]
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: app-dataReadWriteOnce allows mounting read-write from a single node. Multiple Pods on that one node may share the mount if the driver supports it. ReadWriteMany allows read-write mounts from multiple nodes with a compatible provider. ReadWriteOncePod restricts read-write use to a single Pod for supported CSI volumes. Access modes constrain placement and binding. Use an explicit read-only mount or appropriate filesystem permissions where the workload must be prevented from writing.
How many nodes can use this volume?
ReadWriteOnce allows one node to mount read-write. With a supporting driver, more than one Pod on that node may share it.
Read the claim’s access mode
- PVCPVRWO request
ReadWriteOnce asks for read-write mounting on one node and must be supported by the volume.
Mount on the first node
- PVNode 1one node
- Node 1Pod Amount
The driver attaches or mounts according to its implementation and the Pod uses the claim.
Place a second Pod on the same node
- Node 1Pod Bsame-node access
ReadWriteOnce does not itself mean one Pod. Both same-node writers can need application-level coordination.
Check reclaim policy separately
- PVCPVrelease policy
Access modes concern use; reclaim policy concerns what happens after claim release. Neither is a database transaction lock.
Driver supports the illustrated access mode; application consistency is outside mount admission.
Explore another case
Replace the Pod and read the old file
In the persistent storage lab, use the supplied writer manifest to create a complete Pod. Inspect the claim and the bound PV. Record the content of /data/visits, delete only the writer Pod, and recreate it with the same claim. After it starts, look for both the old and new marker. Compare the claim’s bound volume before and after.
kubectl get pvc app-data
kubectl describe pvc app-data
kubectl get pv
kubectl exec writer -- cat /data/visits
# Follow the lab instructions to delete and recreate only the writer Pod.
kubectl get pod writer -o wide
kubectl describe pod writerCheck what happens when a claim is deleted
Deleting a claim releases its volume when no object is protecting it from deletion. The PV’s reclaim policy controls what happens next. Delete normally asks the provisioner to delete the backing storage. Retain leaves the storage for manual recovery or cleanup. Before deleting a claim, check the PV policy and verify you can restore important data from an independent copy.
Check your understanding
The writer was replaced and its report survived. Would the same test establish that the report survives deletion of the PVC?
It establishes persistence across a Pod replacement with the same claim. Deleting the claim exercises the volume’s reclaim behavior. Inspect the PV policy and use a separate disposable copy to test that path.
Primary documentation
Go to the source
Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise