Chapter 7 passed files between containers with an emptyDir. That worked until the Pod was deleted. This chapter is about data that stays.
The writable layer
Every container writes on top of its image, into a layer that belongs to that container alone. Replace the container and the layer is gone. A database in a bare container loses everything on its first restart.
Three kinds of volume
A volume is a directory mounted into the container from outside that layer. The kind decides how long the data lives:
volumes:
- name: scratch
emptyDir: {}
- name: node-logs
hostPath:
path: /var/log
- name: data
persistentVolumeClaim:
claimName: market-dataMounting is the same for all three: a volumeMounts entry in the container with the volume's name and a mountPath.
Which one
| Need | Volume |
|---|---|
| Pass files between containers, cache, temp space | emptyDir |
| A node agent reading the node's own files | hostPath |
| An app's data: database files, uploads, anything you would miss | persistentVolumeClaim |
hostPath is tempting and dangerous: the data sits on one machine, and a Pod that lands on another node sees an empty directory, or someone else's files.
The Pod names a claim; the claim is bound to a volume; the volume is a real disk somewhere. The next lessons take that chain one link at a time.