Mastering Kubernetes Persistent Storage: PV, PVC, and CSI Explained
Learn how Kubernetes abstracts persistent storage using PersistentVolumes (PV) and PersistentVolumeClaims (PVC), why HostPath is limited, the role of network storage, and how to implement CSI drivers with practical YAML examples and kubectl commands for creating and managing PVs and PVCs.
Why HostPath is insufficient
HostPath provides persistent storage but stores data on the node itself, making it suitable only for read‑only scenarios. When a Pod is rescheduled, its data would be lost, so network storage is required.
Kubernetes storage abstraction: PV and PVC
Kubernetes solves this problem by introducing PersistentVolumes (PV) and PersistentVolumeClaims (PVC), decoupling storage from the underlying infrastructure. Users request storage just like CPU or memory.
PV : Describes a persistent storage volume, typically defining a directory on a host such as an NFS mount.
PVC : Describes the desired storage attributes for a Pod, such as size and access mode.
Administrators configure the network storage type and provide corresponding PV specifications. Users simply create a PVC and reference it in a Pod’s volume definition.
Using network storage with CSI
Kubernetes offers the Container Storage Interface (CSI) that allows vendors to develop custom storage plugins, enabling support for block, file, or object storage.
Example: Defining a PersistentVolume
<code>apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-example
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 10Gi
csi:
driver: nas.csi.everest.io
fsType: nfs
volumeAttributes:
everest.io/share-export-location: nas01-mycloud.com:/share-96314776
volumeHandle: 68e4a4fd-d759-444b-8265-20dc66c8c502
</code>Create the PV and inspect it:
<code>$ kubectl create -f pv.yaml
persistentvolume/pv-example created
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM
pv-example 10Gi RWX Retain Available
</code>Understanding PV status fields
RECLAIM POLICY Retain means the PV remains after the PVC is released. STATUS Available indicates the PV is ready for binding.
Example: Creating a PersistentVolumeClaim
<code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-example
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
volumeName: pv-example
</code>Create the PVC and verify its binding:
<code>$ kubectl create -f pvc.yaml
persistentvolumeclaim/pvc-example created
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-example Bound pv-example 10Gi RWX
</code>The PVC is bound to the PV, and the PV status changes to Bound with CLAIM default/pvc-example, illustrating that PVs are cluster‑wide resources while PVCs are namespace‑scoped.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.