Appearance

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.

  1. Write one marker to each mount

    The same process can write to its own filesystem, a Pod-scoped emptyDir and a claim-backed mounted path.

  2. Restart the container

    • Writable layerFresh for a restarted container
    • PV dataUnderlying storage lifecycle

    A new container filesystem starts from the image. The Pod is the same, so its emptyDir and PVC mounts remain available.

  3. Replace the Pod

    • Writable layerFresh for a restarted container
    • emptyDirBelongs to this Pod
    • PV dataUnderlying storage lifecycle

    A replacement has a new Pod identity and new emptyDir. It can refer to the same PVC to recover persistent data.

  4. Read data from the bound volume

    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
A matching volume can bindCapacity, storage class, and availability match. Actual binding also considers access modes, topology, volume mode, and provisioning policy.. PVC, 1 Gi · fast, active. PV volume-a, 3 Gi · fast · available, readyPVC: 1 Gi · fast
PVC1 Gi · fastIn focus
PV volume-a: 3 Gi · fast · available
PV volume-a3 Gi · fast · availableReady
PVC1 Gi · fastIn focus
PV volume-a3 Gi · fast · availableReady
A matching volume can bind

Capacity, storage class, and availability match. Actual binding also considers access modes, topology, volume mode, and provisioning policy.

spec:
  storageClassName: fast
  resources:
    requests:
      storage: 1Gi
Inspect YAML or commands

Inspect the backing resource

kubectl describe pvc app-data
kubectl get pv
Explore 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-data

ReadWriteOnce 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.

  1. Read the claim’s access mode

    ReadWriteOnce asks for read-write mounting on one node and must be supported by the volume.

  2. Mount on the first node

    The driver attaches or mounts according to its implementation and the Pod uses the claim.

  3. Place a second Pod on the same node

    ReadWriteOnce does not itself mean one Pod. Both same-node writers can need application-level coordination.

  4. Check reclaim policy separately

    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.

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 writer

Check 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

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu