liveBook · Manning

Persistent volume

As explained in Road to Kubernetes

A persistent volume is a Kubernetes storage resource that provides durable storage independently of an individual container's lifecycle.

A persistent volume provides durable Kubernetes storage that survives an individual container’s lifecycle. Cloud-managed clusters attach the volume to a cluster node for workloads that need data to persist. section 8.1.3 section 8.4.1

Request and use a persistent volume through a PersistentVolumeClaim (PVC):

  • Set accessModes, such as ReadWriteOnce; supported modes depend on the cloud provider. section 8.4.1
  • Request capacity with resources.requests.storage, such as 10Gi for 10 gigabytes. section 8.4.1
  • Choose a storageClassName, including a class that retains the drive after the PVC is deleted. section 8.4.1
  • Reference the PVC from a Deployment, then mount it into the container filesystem. section 8.4.1

Mount storage in an nginx Deployment

A PVC can request 10Gi with ReadWriteOnce and a retained storage class. An nginx Deployment then claims it and mounts the volume at /usr/share/nginx/html. Apply both resources with kubectl apply -f deploy-pvc/ and inspect the claim with kubectl describe pvc first-pvc. section 8.4.1

Listing 8.14 PersistentVolumeClaim resource
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: first-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: linode-block-storage-retain

Use the manifest to inspect the PVC fields that request and control persistent storage. section 8.4.1

Listing 8.15 Deployment resource with a PVC
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  ...
  template:
    ...
    spec:
      ...
      containers:
      - name: nginx
        ...
        volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: first-pv-storage
      volumes:
      - name: first-pv-storage
        persistentVolumeClaim:
          claimName: first-pvc

Use the Deployment manifest to trace the PVC from the pod specification to its container mount path. section 8.4.1

How Road to Kubernetes covers it

How deep it goes
Explains PVC configuration, provider limitations, retention classes, Deployment attachment, mounting, application, and verification.
Examples
Uses a 10Gi nginx Deployment with ReadWriteOnce storage mounted at /usr/share/nginx/html.
What it assumes
Assumes basic Kubernetes resources and containers while introducing PVC fields, storage classes, access modes, and volume mounts.
What you can do after
Operate/configure persistent storage by defining a PVC, attaching it to a Deployment, mounting it, and verifying provisioning.
How it connects
Connects Kubernetes storage with PersistentVolumeClaim, Deployments, Pods, containers, StatefulSets, and cloud providers.

Also explained in

Compare how 7 books explain persistent 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.