A volume in Kubernetes is a directory accessible to all containers running in a pod, with the additional guarantee that the data is preserved across restarts of individual containers.
Depending on what is backing the volume and potentially additional semantics present, we differentiate the types of volumes:
Node-local volumes, such as
Generic networked volumes, such as
Cloud provider–specific volumes, such as
Special-purpose volumes, such as
Which volume type you choose depends entirely on your use case. For example, for a temporary scratch space, an
emptyDir would be fine, but when you need to make sure your data survives node failures you’ll want to look into networked volumes, or cloud-provider–specific ones if you run Kubernetes in a public cloud setting.
You have two or more containers running in a pod and want to be able to exchange data via filesystem operations.
Use a local volume of type
The starting point is the following pod manifest, exchangedata.yaml, which has two containers (
c2) that each mount the local volume
xchange into their filesystem, using different mount points: