Persistent Volume
Persistent Volume Claim
Kubernetes Storage
DevOps
Cloud Computing

What is the difference between persistent volume PV and persistent volume claim PVC in simple terms?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

In the world of Kubernetes, understanding the concepts of Persistent Volume (PV) and Persistent Volume Claim (PVC) is crucial for managing storage. Let’s dive into these terms and grasp their significance in Kubernetes storage architecture.

Persistent Volume (PV)

A Persistent Volume is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. PVs are cluster resources that exist independently of pods, meaning their lifecycle is separate from any particular pod that uses them.

Characteristics of PV:

  • Provisioning: Manual or dynamic provisioning via Storage Classes.
  • Lifecycle: Exists independently of the pod.
  • Storage: Can be backed by various storage systems like NFS, iSCSI, cloud provider-specific storage solutions, etc.
  • Capacity: Typically defined in terms of size (e.g., 10Gi).
  • Access Modes: Defines how the volume can be accessed: ReadWriteOnce, ReadOnlyMany, or ReadWriteMany.

Example:

yaml
1apiVersion: v1
2kind: PersistentVolume
3metadata:
4  name: my-pv
5spec:
6  capacity:
7    storage: 10Gi
8  accessModes:
9    - ReadWriteOnce
10  persistentVolumeReclaimPolicy: Retain
11  hostPath:
12    path: /mnt/data

Persistent Volume Claim (PVC)

A Persistent Volume Claim is a request for storage by a user. PVCs are used to consume the PV resources. Much like a pod uses node resources, a PVC uses PV resources. It allows users to request storage without needing to understand the underlying storage details.

Characteristics of PVC:

  • Request: PVCs request specific sizes and access modes.
  • Binding: A PVC binds to a suitable PV that matches its requirements.
  • Usage: Once a PV is bound to a PVC, the PV becomes claimed and can be used by pods.

Example:

yaml
1apiVersion: v1
2kind: PersistentVolumeClaim
3metadata:
4  name: my-pvc
5spec:
6  accessModes:
7    - ReadWriteOnce
8  resources:
9    requests:
10      storage: 10Gi

Differences Between PV and PVC

The core difference between a Persistent Volume and a Persistent Volume Claim revolves around their roles and how they relate to each other in Kubernetes.

AspectPersistent Volume (PV)Persistent Volume Claim (PVC)
RoleResourceRequest
ProvisioningManually by admin or dynamically via Storage ClassCreated by the user
LifecycleExists independently of any podExists dependent on user requirements
Capacity AssignmentDefines the capacity and access modesRequests specific capacity and access modes
BindingBinds to PVCs when their requirements matchBinds to a suitable PV once requested
AccessDefined by the adminDefined by the user

How PV and PVC Work Together

When a pod needs to consume storage, a PVC is created to request storage of a certain size and access type. The Kubernetes master watches for new PVCs and finds a suitable PV that can fulfill the PVC requirements. Once a suitable PV is found, it gets bound to the PVC, making it ready for use by pods.

Use Cases and Benefits

  • Decoupling: PV and PVC allow separation of storage provisioning and consumption, making it easier to manage storage resources.
  • Flexibility: Users can request storage without needing to understand the underlying infrastructural details.
  • Dynamic Provisioning: When combined with Storage Classes, PVs can be dynamically provisioned based on PVC requirements.
  • Persistence: Data continues to persist even if the pod using the PV is terminated, ensuring data availability.

Conclusion

Understanding Persistent Volumes and Persistent Volume Claims is key to effectively managing stateful applications in Kubernetes. PVs define the "what" (the actual storage medium), whereas PVCs define the "how" and "how much" (the user's requirement for storage). Together, they facilitate efficient and flexible storage management in a Kubernetes environment, enabling applications to maintain state consistency across various operational scenarios.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design