PV & PVC
A PersistentVolume (PV) is a storage resource in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes.
Persistent Volumes are Kubernetes objects that represent storage resources in your cluster.
PVs work in conjunction with Persistent Volume Claims (PVCs), another type of object which permits Pods to request access to PVs.
To successfully utilize persistent storage in a cluster, you’ll need a PV and a PVC that connects it to your Pod.
The primary role of PVs is to abstract away the differences between cluster storage implementations.
Each PV is assigned a storage class which defines the type of storage it provisions.
Storage classes allow the automatic provisioning of volumes through many different storage providers, including cloud-hosted block storage options such as AWS Elastic Block Store and GCE Persistent Disk.
Types of Persistent Volume
Kubernetes supports several Persistent Volume types that alter where and how your data is stored:
local
– Data is stored on devices mounted locally to your cluster’s Nodes.hostPath
– Stores data within a named directory on a Node (this is designed for testing purposes and doesn’t work with multi-Node clusters).nfs
– Used to access Network File System (NFS) mounts.iscsi
– iSCSI (SCSI over IP) storage attachments.csi
– Allows integration with storage providers that support the Container Storage Interface (CSI) specification, such as the block storage services provided by cloud platforms.cephfs
– Allow the use of CephFS volumes.fc
– Fibre Channel (FC) storage attachments.rbd
– Rados Block Device (RBD) volumes
Persistent Volume Access Modes
Persistent Volumes support four different access modes that define how they’re mounted to Nodes and Pods:
ReadWriteOnce (RWO)
– The volume is mounted with read-write access for a single Node in your cluster. Any of the Pods running on that Node can read and write the volume’s contents.ReadOnlyMany (ROX)
– The volume can be concurrently mounted to any of the Nodes in your cluster, with read-only access for any Pod.ReadWriteMany (RWX)
– Similar to ReadOnlyMany, but with read-write access.ReadWriteOncePod (RWOP)
– This new variant, introduced as a beta feature in Kubernetes v1.27, enforces that read-write access is provided to a single Pod. No other Pods in the cluster will be able to use the volume simultaneously.
The lifecycles of PVs and PVCs
Provision
At the Provisioning stage, the PV is created and its storage is allocated using the selected driver.
Provisioning can occur manually by creating a PersistentVolume object in your cluster, or dynamically, by adding a PVC that refers to an unknown PV. After provisioning, the PV will exist in your cluster, but won’t be actively providing storage.
Binding
Binding occurs when a cluster user adds a PVC that claims the PV. The PV will enter this state automatically when dynamic provisioning is used, because you’ll have already created the PVC.
Kubernetes automatically watches for new PVCs and binds them to the PVs they reference. Each PV can only be bound to a single PVC at a time. Once a PVC claims a PV, the volume will be Bound, but won’t necessarily be used by a Pod.
Use
A volume enters use once its PVC is consumed by a Pod. When Pods reference PVCs, Kubernetes automatically mounts the correct volume into the Pod’s filesystem. In this state, the PV is actively providing storage to an application in your cluster.
Reclaim
Storage isn’t always required indefinitely. Users can delete the PVC to relinquish access to the PV. When this happens, the storage used by the PV is “reclaimed.”
The reclaim behavior is customizable and allows you to either delete the provisioned storage, recycle it by emptying its contents, or retain it as-is for future reuse.
Sample File
PV.yml
PVC.yml
Last updated