Chapter 8. Volumes and Configuration Data
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
emptyDirorhostPath -
Generic networked volumes, such as
nfs,glusterfs, orcephfs -
Cloud provider–specific volumes, such as
awsElasticBlockStore,azureDisk, orgcePersistentDisk -
Special-purpose volumes, such as
secretorgitRepo
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.
8.1 Exchanging Data Between Containers via a Local Volume
Problem
You have two or more containers running in a pod and want to be able to exchange data via filesystem operations.
Solution
Use a local volume of type emptyDir.
The starting point is the following pod manifest, exchangedata.yaml, which has two containers (c1 and c2) that each mount the local volume xchange into their filesystem, using different mount points:
apiVersion:v1kind:Podmetadata:name:sharevolspec:containers:-name:c1image:centos:7command:-"bin/bash"-"-c"-"sleep ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access