liveBook · Manning

Chapter 9: Adding volumes for storage, configuration, and metadata

What you will learn in chapter 9 of Kubernetes in Action, Second Edition

The introduction explains why storage volumes commonly accompany containers in a pod: they hold data and let containers share files.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why storage volumes commonly accompany containers in a pod: they hold data and let containers share files.

Key terms: pod, containers, storage volumes

9.1 Introducing volumes

This section explains why container file changes disappear on restart and introduces pod volumes as a way to preserve files by mounting them into a container.

Key terms: pod, container image, isolated filesystem, volume, mounting, file tree

9.1.1 Understanding when to use a volume

The section uses a Quiz service to show why MongoDB data must be stored outside its container to survive container recreation.

Key terms: Quiz API, MongoDB, questions collection, kiada database, container’s filesystem, container image, volume, container restarts

9.1.2 Understanding how volumes fit into pods

This section explains how pod volumes are mounted, what data they can retain or share, and how volume types determine where that data comes from.

Key terms: volume, pod life cycle, container restart, container image, application’s state, locally cached data, self-healing capability, crash loop, pod volumes, mount

9.2 Using an emptyDir volume

This section introduces emptyDir as an initially empty volume that keeps files for a pod’s lifetime and supports temporary writes or file sharing within a pod.

Key terms: emptyDir, volume, pod, read-only

9.2.1 Persisting files across container restarts

This subsection shows how to mount an emptyDir volume for MongoDB data, what survives a container restart, and how to configure the volume’s storage medium and size.

Key terms: emptyDir, spec.volumes, volumeMounts, mountPath, quiz-data, /data/db, container restart, pod deletion, host node’s filesystem, medium

9.2.2 Initializing an emptyDir volume

This section shows how to populate an emptyDir volume before the quiz application starts, using an init container or short file contents defined in the Pod manifest.

Key terms: emptyDir volume, init container, initdb volume, insert-questions.js, /docker-entrypoint-initdb.d/, quiz-data, pod manifest, inline

9.2.3 Sharing files between containers

Shows how an emptyDir volume lets a quote-writing container and an Nginx container share a file, and notes a startup timing issue.

Key terms: emptyDir volume, quote-writer, nginx container, shared volume, init container, initial quote

9.3 Mounting a container image as a volume

This section motivates using a container image to provide prepared files to other containers and explains why the ImageVolume feature gate may need to be enabled.

Key terms: container image, volume, model weights, ImageVolume feature gate, feature gate, cluster administrator

9.3.1 Introducing the image volume type

This subsection explains how a read-only OCI image volume replaces an init-container-populated emptyDir volume for supplying MongoDB startup data.

Key terms: image volume, OCI image, container image, emptyDir volume, init container, insert-questions.js, quiz-questions image, pod volumes

9.4 Accessing files on the worker node’s filesystem

This section explains why system-level pods may need access to a worker node’s filesystem and identifies hostPath as the volume type that provides it.

Key terms: system-level pods, node’s filesystem, hostPath volume type

9.4.1 Introducing the hostPath volume

Introduces hostPath volumes as node-local filesystem mounts, explaining when they are useful, why they are unsuitable for movable database pods, and the security risk they create.

Key terms: hostPath volume, host node, worker node, system-level logs, privileged pods, Docker socket file

9.4.2 Using a hostPath volume

This subsection uses a hostPath volume to show how a pod can access a worker node’s filesystem, then explains hostPath type checks and their security implications.

Key terms: hostPath volume, host node, worker node, hostPath type, FileOrCreate, DirectoryOrCreate, pod events, Kubelet

9.5 ConfigMap, Secret, Downward API, and projected volumes

Introduces file-based delivery of configuration and sensitive data through volumes, using the Envoy sidecar to explain why these files should not be baked into an image.

Key terms: ConfigMap, Secret, volume, Envoy sidecar, TLS certificate, private key

9.5.1 Using a configMap volume to expose ConfigMap entries as files

This section shows how to expose ConfigMap entries as files in a pod, including what happens when the ConfigMap is missing, how file updates behave, and how to include only selected entries.

Key terms: configMap volume, ConfigMap entries, mount, optional: true, environment variables, items, key, path

9.5.2 How configMap volumes work

This section explains how configMap volume mounts affect existing files, how Kubernetes updates volume files atomically, and why subPath mounts behave differently.

Key terms: configMap volume, mountPath, subPath, symbolic links, ..data, timestamped directory, atomic updates, symbolic link

9.5.3 Using Secret volumes

This section shows how to mount a Secret as files in a pod, what the container reads from those files, and why this can replace a custom image.

Key terms: secret volume, volumeMount, secretName, kiada-tls Secret, Secret entry, Base64-encoded, kiada-ssl-proxy, envoyproxy/envoy, container image, tmpfs

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

This section explains how to set and inspect file permissions in Secret and ConfigMap volumes, and how to keep restricted files accessible to container processes.

Key terms: secret volume, configMap volume, defaultMode, mode, 0644, symbolic links, ls -lL, target file permissions, UID, GID

9.5.5 Using a downwardAPI volume to expose Pod metadata as files

Shows how to expose Pod metadata as files through a downwardAPI volume and how to reference Pod and container resource fields in that volume.

Key terms: downwardAPI volume, metadata.name, volumeMount, fieldRef, resourceFieldRef, containerName, divisor

9.5.6 Using projected volumes to combine volumes into one

This section explains how projected volumes combine files from multiple sources in one directory, then describes the automatically added kube-api-access projected volume.

Key terms: projected volume, subPath, ConfigMap, Secret, Downward API, etc-envoy, kiada-ssl-config, kiada-tls, read-only, kube-api-access

9.6 Other volume types at a glance

This section surveys additional Kubernetes volume types, contrasting persistentVolumeClaim and ephemeral volumes and explaining why CSI-backed storage is usually accessed through those abstractions.

Key terms: persistentVolumeClaim, ephemeral, PersistentVolume, csi, Container Storage Interface, CSI driver

9.7 Summary

Summarizes how pod volumes provide mounted storage and files, and distinguishes the uses and risks of the volume types covered in the chapter.

Where this is used later

Concepts explained in this chapter

← Chapter 8: Configuring applications with ConfigMaps and Secrets Chapter 10: Persisting data with PersistentVolumes →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.