Sobes.tech
Middle

What is a Persistent Volume (PV) and Persistent Volume Claim (PVC)?

sobes.tech AI

Answer from AI

Persistent Volume (PV) is an abstraction in Kubernetes representing a piece of storage in the cluster that has been specifically provisioned by an administrator. PV is a cluster resource and exists independently of the pod lifecycle.

Persistent Volume Claim (PVC) is a request by a pod to consume a specific amount of storage with certain access modes and performance characteristics. PVC is bound to a PV that satisfies its requirements.

Main characteristics:

  • PV: A cluster resource managed by the administrator. Describes a physical or network data carrier (NFS, iSCSI, cloud storage, etc.). Has a lifecycle independent of pods.
  • PVC: A user (developer) request for the necessary amount of storage. Bound to an available PV. Specifies requirements (size, access rights).

Lifecycle of PV/PVC:

  1. Provisioning: The administrator creates a PV or Kubernetes dynamically creates it based on StorageClass.
  2. Binding: PVC searches for a suitable PV based on requirements (size, access modes). If found, binding occurs.
  3. Using: The pod uses the PVC by mounting it into the container.
  4. Releasing: PVC is deleted. PV can be released or remain reserved (based on policy).
  5. Recycling/Deleting/Retaining: The cleanup policy of PV after PVC is released.

Example PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: nfs.example.com
    path: "/exported/path"

Example PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-app-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

Usage: The pod references the PVC in its specification to mount the volume.