9 Adding Volumes for Storage, Configuration, and Metadata
This chapter covers
- How to add a volume to a Pod and mount it into its containers
- Persisting state across container restarts using an emptyDir volume
- Sharing files between containers within the same pod
- Mounting files into a container from another container image
- Accessing the host node’s filesystem from within a pod
- Exposing ConfigMaps, Secrets, and the Pod metadata through volumes
The previous chapters focused on the Pod’s containers, but they are only half of what a pod typically contains. Containers in a Pod are typically accompanied by storage volumes that allow the containers to store data for the lifetime of the pod or beyond, or to share files with the other containers of the pod. This is the focus of this chapter.
Note
You’ll find the code files for this chapter at https://github.com/luksa/kubernetes-in-action-2nd-edition/tree/master/Chapter09
9.1 Introducing volumes
A pod is like a small logical computer that runs a single application. This application can consist of one or more containers that run the application processes. These processes share computing resources such as CPU, RAM, network interfaces, and others. In a typical computer, the processes use the same filesystem, but this isn’t the case with containers. Instead, each container has its own isolated filesystem provided by the container image.