Lesson 2 · Unit 03
Storage
Volumes, claims that bind to them, and StatefulSets in outline.
What you practise
- Volumes, claims against volumes, pods with identity (StatefulSets) in outline
Try a question from this lesson
Pick one
A database runs in a Pod and writes its files inside the container's own filesystem. The container crashes and the kubelet restarts it. What is in the data directory now?
Hint
Recall where a container's own writes go, and what a new container is built from.
Correct answer
Only what the image contains: the data is gone
Why
A restarted container starts clean from its image, exactly as in the Docker roadmap: the writable layer belonged to the old container. Data that must outlive a container has to live outside it, in a volume.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Volumes, and storage that outlives a Pod
A volume is a directory supplied by the Pod and mounted into its containers.
The simplest kind, emptyDir, starts empty and lasts as long as the Pod. It survives a container restart, but is deleted with the Pod.
Data that must survive the Pod needs storage that exists apart from it. A PersistentVolume is a piece of real storage in the cluster. A PersistentVolumeClaim is a request for one: this much space, mounted this way.
Concept
From claim to mounted directory
A claim is bound to exactly one volume that satisfies it. That volume was either made in advance by an administrator, or is created on demand by a StorageClass, which knows how to provision storage.
The Pod never names the volume. It names the claim, and mounts it at a path. Replace the Pod, and the new one names the same claim and finds the same data.
spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: db-data
containers:
- name: db
image: shop/db:3.2
volumeMounts:
- name: data
mountPath: /var/lib/dbConcept
StatefulSet, in outline
A Deployment's Pods are interchangeable: random names, any order, one template, so they would all share one claim. A replicated database needs each copy to keep its own identity and its own data.
A StatefulSet gives each Pod a fixed, numbered name, creates them in order, and makes one claim per Pod from a template. When db-1 is replaced, the new Pod is db-1 again and gets its storage back.
StatefulSet db, replicas 3
db-0 claim data-db-0
db-1 claim data-db-1
db-2 claim data-db-28 more exercises in the app
- 3× multiple choice
- 1× fill the blanks
- 1× order the lines
- 1× true or false
- 1× match the pairs
- 1× type the answer
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.