liveBook · Manning

Volume

As explained in Road to Kubernetes

A storage volume is a storage resource attached to an application environment for retaining and accessing data.

A storage volume is the stateful part of an application environment: an attached resource that lets an application read and write data while its container remains stateless. This makes volumes essential for practical data stores such as databases and message queues. section 8.4.2

In Kubernetes, a StatefulSet can attach a separate volume to each Pod replica through a volume template. A Postgres deployment requests 20Gi of storage, mounts it at /var/lib/postgresql, and uses an init container to remove the volume's lost+found directory. section 8.4.2

Listing 8.18 StatefulSet for Postgres, part 2
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      ...
    spec:
      ...
  volumeClaimTemplates:
  - metadata:
      name: db-vol
    spec:
      storageClassName: linode-block-storage-retain
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 20Gi

Inspect the volumeClaimTemplates configuration that requests storage and defines the storage class and access mode. section 8.4.2

How Road to Kubernetes covers it

How deep it goes
Explains attachment through StatefulSets and demonstrates claims, mounts, storage requests, and initialization, without covering clustered databases.
Examples
Uses a Postgres StatefulSet with a 20Gi claim, mounted storage, and a lost+found cleanup init container.
What it assumes
Assumes basic containers and Pods, while introducing persistent versus stateless application data through deployment examples.
What you can do after
Operate/configure persistent storage by declaring claims, mounting volumes, and attaching them to StatefulSet Pods.
How it connects
Connects volumes with StatefulSets, Pods, persistent storage, containers, databases, and message queues.

Also explained in

Compare how 8 books explain volume →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.