Lifetimes
Where a program writes decides how long the data lives
Container files: lost at restart. emptyDir: with the pod. Persistent: kept.
Before choosing storage, ask how long the data must live. Here is one hour in the life of a pod. Its container crashes at twenty past ten, and the whole pod is replaced at twenty to eleven. Files written inside the container are lost at every restart. Three separate lives. An empty dir volume belongs to the pod. It survives the crash, but not the replacement. A persistent volume is separate from any pod, and carries straight through.
Claims and volumes
A claim asks for storage; the cluster finds or makes it
A claim is the request. A volume is the disk. They are bound.
Persistent storage involves three objects, and it helps to see who makes each. A pod needs a disk. You write a claim: ten gibibytes, that one node can read and write. That is all you say. A storage class, set up by whoever runs the cluster, sees the claim. It creates a real disk in the cloud, and a volume object to represent it. The claim and the volume are bound together, one to one. And the pod mounts the claim.
Claims and volumes · Going deeper · 1 of 2
The claim, and a pod that uses it
A claim for 1Gi, and a pod that mounts it at /data.
StorageClass · Going deeper · 2 of 2
A StorageClass as written: four fields decide what a claim gets
provisioner, reclaimPolicy, volumeBindingMode, allowVolumeExpansion.
Moving
When a pod moves, its disk follows it
The disk is re-attached, not copied. But it cannot leave its zone.
What makes this worth the trouble is what happens on a bad day. The database pod runs on node A, with its disk attached to that machine. Node A fails. Kubernetes starts the pod again on node B, detaches the disk from the dead node, and attaches it to the new one. Nothing is copied, and nothing is lost. There is one limit. The disk lives in zone A. Node C is in another zone, so the pod could never have been placed there.
Moving · Going deeper
Lab: data that outlives its pod
Write a file, delete the pod, read the file from a new one.
Access modes
The access mode says how many nodes may mount at once
ReadWriteOnce for disks. ReadWriteMany needs a file share.
Every claim states an access mode, and it is about nodes. Read write once: one node may mount the volume. This is what an ordinary cloud disk can do. Read only many: any number of nodes, but nobody writes. Read write many: every node reads and writes at once. Only shared file systems offer this. And read write once pod is the strictest: one pod, and no other, anywhere.
Static volumes · Going deeper
A hand-made volume binds only if class, mode and size all fit
Same storageClassName, a mode on offer, and capacity at least the request.
Reclaim
Deleting the claim may erase the disk
Policy Delete: the disk goes too. Policy Retain: it is kept.
One last question: what happens to the data when you are finished? Deleting a pod is always safe, because the claim remains. Deleting the claim is another matter. With the policy called delete, which is what most storage classes give you, the volume is removed and the disk is erased. With the policy called retain, the volume is kept and marked as released, and the disk keeps its data until an administrator deals with it.
Reclaim · Going deeper · 1 of 2
StatefulSets: a claim for every replica
Each replica has its own claim, and gets it back when replaced.
Volume phases · Going deeper · 2 of 2
Available, Bound, Released: and Released does not bind again
A Released volume keeps its old claimRef until someone clears it.
Lesson complete
You finished “Storage”
Nicely done.