PersistentVolume
A cluster-level storage resource
A cluster-level storage resource
PersistentVolume (PV) is an abstraction of a cluster-level storage resource in Kubernetes. It is used when data must persist even after a Pod is deleted (databases, file storage, etc.). It is provisioned by an administrator or created dynamically through a StorageClass.
Alongside PV, there is a concept called PersistentVolumeClaim (PVC). A PV is the actual storage (NFS, AWS EBS, GCE PD, etc.), and a PVC is the way a user requests storage. When a PVC is created, it is bound to a PV that meets its conditions, or a StorageClass dynamically creates a new PV.
A PV's accessModes include ReadWriteOnce (read/write on a single node), ReadOnlyMany (read on multiple nodes), and ReadWriteMany (read/write on multiple nodes). AWS EBS supports only RWO, while NFS and EFS support RWX.
reclaimPolicy defines how a PV is handled when its PVC is deleted. The options are Retain (manual deletion required), Delete (automatic deletion), and Recycle (reuse after deleting data, deprecated). In production, Retain is recommended to prevent loss of important data.
# PersistentVolume 정의 (관리자가 생성)
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-database
labels:
type: ssd
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: fast-ssd
# AWS EBS 사용 예시
awsElasticBlockStore:
volumeID: vol-0abc123def456
fsType: ext4
---
# PersistentVolumeClaim (개발자가 요청)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-pvc
namespace: production
spec:
accessModes:
- ReadWriteOnce
storageClassName: fast-ssd
resources:
requests:
storage: 50Gi # PV 용량 이하로 요청
selector:
matchLabels:
type: ssd
---
# Pod에서 PVC 사용
apiVersion: v1
kind: Pod
metadata:
name: postgres
spec:
containers:
- name: postgres
image: postgres:15
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
volumes:
- name: data
persistentVolumeClaim:
claimName: database-pvc
"Let's deploy PostgreSQL as a StatefulSet and attach a separate PVC to each Pod with volumeClaimTemplates. Let's set the StorageClass to gp3 SSD and the reclaimPolicy to Retain so that we don't accidentally lose data."
"The relationship between PV and PVC is an abstraction that separates cloud resources from user requests. Administrators provision storage, and developers only need to request the capacity and performance they need. With a StorageClass, dynamic provisioning automates this process."
"The PVC is in Pending status. I checked with kubectl describe pvc, and provisioning failed in the StorageClass. We need to check whether the EBS CSI driver Pod is healthy and whether the IAM permissions are in place. If volumeBindingMode is WaitForFirstConsumer, binding happens only after the Pod is scheduled."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
AWS EBS supports only ReadWriteOnce. To mount it on multiple Pods at the same time, use EFS (which supports RWX). Likewise, GCE PD requires Filestore.
EBS is tied to a specific AZ. If a Pod is scheduled on a node in a different AZ, the volume cannot be mounted. Set volumeBindingMode to WaitForFirstConsumer so that the volume is created after the Pod is scheduled.
Configure important data with reclaimPolicy: Retain, take regular backups with volumeSnapshot, and make it expandable with allowVolumeExpansion: true. You should also check compatibility between the CSI driver version and the Kubernetes version.