Problem statement
Namespace ledger-store runs ledger-api, and its data directory is a path on the node - mounted straight off whatever host the pod happened to land on. Nobody asked for that space, nothing accounts for it, no other part of the cluster knows it is in use, and the pod is quietly pinned to one machine by a directory nobody chose. The ledger written there is real data. Give it storage the cluster actually knows about.
About this exercise
Kubernetes separates the request for storage from the storage. A PersistentVolume (PV) is a piece of storage in the cluster - cluster-scoped, existing in its own right, with a capacity, an access mode and a reclaim policy. A PersistentVolumeClaim (PVC) is a namespaced request for one: this much space, in this access mode, of this class. A pod never names a volume; it names a claim, and the cluster decides which volume satisfies it. That indirection is what makes the pod portable.
Dynamic provisioning removes the last manual step. A StorageClass names a provisioner, and when a claim asks for that class the provisioner creates a volume to fit it. Nobody pre-builds volumes; the claim causes one to exist. One class in the cluster is marked default, and a claim that names no class gets that one. kubectl get storageclass shows the classes and, for each, two decisions that matter here:
- The binding mode decides when a volume is created. With immediate binding, a claim is satisfied the moment it is made. With WaitForFirstConsumer, the claim sits Pending until a pod actually uses it - so the provisioner can place the volume where the pod was scheduled. A Pending claim with no consumer is that mode working, not a failure.
- The access mode is what the claim asks for and the volume grants: ReadWriteOnce means one node may mount it read-write, ReadOnlyMany and ReadWriteMany are the wider grants. A claim only binds to a volume that can grant what it asked for.
Once bound, the claim and the volume point at each other: the claim carries the volume's name, the volume carries a claimRef back. kubectl explain pvc.spec lists every field of a claim.
How this project is graded
The grader reads the claim, the volume it bound to and the pod back off the live cluster and compares them against the specification below - the requested size and mode, the provisioner that made the volume, and the two references matching each other. Then it reads the ledger from inside the running container to see whose writes are on the volume. Nothing in ledger-store is deleted or patched by the grader. If ledger-api is missing it is re-seeded on the node path it uses today, so a half-finished replacement is graded as still borrowing the host.
What you will build
A claim, and a pod that uses it. The container, its image and its command stay exactly as they are - manifest.yaml holds the pod as it runs today.
PersistentVolumeClaim ledger-data in namespace ledger-store storage class the cluster's default class access mode ReadWriteOnce size 256MiPod ledger-api takes its /var/lib/ledger directory from the claim ledger-data instead of from a directory on the node
The container writes boots and ledger.log into that directory on every start, appending a line ledger opened generation <n>. You decide what the directory is.
Step 1 - ask for the space
Create ledger-data with the size, mode and class above. Until something consumes it the claim will sit Pending - read the class's binding mode and you will know why.
claim_requests_the_specified_size_and_access_mode should pass
Step 2 - consume the claim
Replace ledger-api so its data directory comes from ledger-data. The claim binds, a volume is provisioned to fit it, and the two must report each other.
claim_binds_to_a_dynamically_provisioned_volume, pod_mounts_the_claim_and_the_ledger_reads_back and claim_and_volume_report_bound_with_matching_references should pass
Step 3 - prove the bytes are not the pod's
Replace ledger-api again, leaving the claim alone. The container that comes up has to find ledger opened generation 1 already on the volume and append generation 2 next to it.
the_dataset_outlives_the_pod_that_wrote_it should pass
When every test passes
You have:
- A ledger on storage the cluster provisioned, sized and accounted for, instead of on a directory nobody chose
- A pod that names a request rather than a machine
- A claim and a volume that report each other, so the binding is a fact and not an assumption
- Proof that deleting the consumer does not delete the data
You do not have yet:
- Any answer to what happens when the claim goes away. Reclaim policy, handoff and the claims that can never be satisfied are the next exercise.
Verify
Click Test after every step.
