liveBook · Manning

Persistent volume claim

As explained in Data Pipelines with Apache Airflow, Second Edition

A persistent volume claim is a Kubernetes resource request for persistent storage with specified capacity and access requirements.

A persistent volume claim is a Kubernetes resource request for storage that containers can use beyond an individual task process. In an Airflow workflow running tasks as Kubernetes pods, the claim makes shared task data available through Kubernetes rather than through the Airflow worker. section 11.5.2 section 11.5.5

A claim specifies the storage class, access mode, and requested capacity. A matching PersistentVolume can provide the storage. For example, the data-volume configuration requests 1Gi with ReadWriteOnce and uses the manual storage class; the accompanying local volume maps storage to /tmp/data. section 11.5.2

Create storage for Airflow task pods

Apply the storage definition in the Airflow namespace: kubectl --namespace airflow apply -f resources/data-volume.yml. Kubernetes then creates data-volume as both a PersistentVolumeClaim and a PersistentVolume. Airflow task pods can mount the claim to store task results. section 11.5.2

A missing or incorrectly created claim prevents a task pod from starting. When logs show a pod stuck in Pending, inspect the pod with kubectl describe and read its Events. Applying the storage definition can resolve errors such as persistentvolumeclaim data-volume not found or an unbound claim. section 11.5.4

Listing 11.19 YAML specification for storage
apiVersion: v1
kind: PersistentVolume     #1
metadata:
 name: data-volume         #2
 Labels:
   type: local
Spec:
 storageClassName: manual
 capacity:
   storage: 1Gi            #3
 accessModes:
   - ReadWriteOnce         #4
 hostPath:
   path: "/tmp/data"       #5
---
apiVersion: v1
kind: PersistentVolumeClaim      #6
metadata:
 name: data-volume         #7
spec:
 storageClassName: manual
 accessModes:
   - ReadWriteOnce         #8
 resources:
   requests:
     storage: 1Gi          #9

Inspect the complete PersistentVolume and PersistentVolumeClaim YAML, including storage class, capacity, access mode, and host path. section 11.5.2

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Defines capacity and access settings, demonstrates deployment, and diagnoses pending pods, but does not detail storage backends.
Examples
Uses a 1Gi data-volume claim, ReadWriteOnce access, a local hostPath, kubectl apply, and pod Events.
What it assumes
Assumes a functioning Kubernetes cluster and namespace, while demonstrating the storage YAML and kubectl commands needed to create the resources.
What you can do after
Operate/configure Kubernetes storage for Airflow pods and diagnose scheduling failures caused by missing or unbound claims.
How it connects
Connects PersistentVolumeClaim with PersistentVolume, Kubernetes pods, Airflow, and KubernetesPodOperator scheduling.

Also explained in

Compare how 9 books explain persistent volume claim →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.