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

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.

9.1.1 Understanding when to use a volume

9.1.2 Understanding how volumes fit into pods

9.2 Using an emptyDir volume

9.2.1 Persisting files across container restarts

9.2.2 Initializing an emptyDir volume

9.2.3 Sharing files between containers

9.3 Mounting a container image as a volume

9.3.1 Introducing the image volume type

9.4 Accessing files on the worker node’s filesystem

9.4.1 Introducing the hostPath volume

9.4.2 Using a hostPath volume

9.5 ConfigMap, Secret, Downward API, and Projected volumes

9.5.1 Using a configMap volume to expose ConfigMap entries as files

9.5.2 How configMap volumes work

9.5.3 Using Secret volumes

9.5.4 Setting file permissions and ownership in a secret/configMap volume

9.5.5 Using a downwardAPI volume to expose pod metadata as files

9.5.6 Using projected volumes to combine volumes into one

9.6 Other volume types at a glance

9.7 Summary