Skip to content

PersistentVolume (PV)

A PersistentVolume (PV) is a storage resource within a Kubernetes cluster that represents a piece of storage provisioned by an administrator or dynamically provisioned using Storage Classes^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md, 400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md]. It is a cluster-level resource, distinct from the compute resources (like CPU or memory) that Pods use^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md].

The actual storage can be backed by various mediums, including Network File Systems (NFS), cluster node storage, or cloud storage services^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].

Lifecycle and Independence

The defining characteristic of a PV is that it possesses a lifecycle independent of any individual Pod that uses it^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md]. Unlike emptyDir volumes, which are ephemeral and deleted when a Pod is terminated, a PV persists data beyond the lifespan of the Pod^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md]. This independence ensures that data remains intact even if the consuming Pod is rescheduled or deleted^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].

Relationship with [[PersistentVolumeClaim (PVC)]]

While the PV represents the actual storage hardware or resource, users interact with it via a PersistentVolumeClaim (PVC)^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md]. A PVC functions as a request for storage by a user, analogous to how a Pod requests compute resources (CPU or RAM)^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md]. The PVC acts as the bridge that consumes specific quotas or limits defined by the PV^[400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md].

Once a PVC is created, it continuously searches for a PV that meets its requirements (such as size and access mode) and binds to it^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md]. If no matching PV is found, the PVC remains in a Pending state indefinitely^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].

Access Modes

PVs support specific access modes that define how they can be mounted by nodes^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md]:

  • ReadWriteOnce (RWO): The volume can be mounted as read-write by a single node^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  • ReadOnlyMany (ROX): The volume can be mounted as read-only by many nodes^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  • ReadWriteMany (RWX): The volume can be mounted as read-write by many nodes^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  • ReadWriteOncePod: The volume can be mounted as read-write by a single Pod^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].

Persistent Volume Phases

The status of a PV can transition through several phases^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md]:

  1. Available: A free resource in the cluster that has not yet been bound to a claim^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  2. Bound: The volume has been bound to a PVC^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  3. Released: The PVC has been deleted, but the resource has not yet been reclaimed by the cluster^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  4. Failed: The automatic reclamation failed^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].

Reclaim Policies

When a PVC is deleted, the PV enters the Released state. The subsequent behavior of the storage asset is determined by its reclaim policy^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md]:

  • Retain: Manual reclamation is required^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  • Delete: The underlying storage asset (e.g., AWS EBS, GCE PD) is deleted along with the PV^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].
  • Recycle (Deprecated): Data is scrubbed (rm -rf /thevolume/*) and the volume is made available again^[400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md].

Sources

  • 400-devops__06-Kubernetes__k8s-ithelp__Day16__README.md
  • 400-devops__06-Kubernetes__k8s-ithelp__Day20__README.md