Volumes: Persistent Storage in Kubernetes

mesrar

Mesrar

Posted on February 1, 2024

Volumes: Persistent Storage in Kubernetes

Viewing Persistent Volumes (PV) and Persistent Volume Claims (PVC)

To check details about Persistent Volumes and Persistent Volume Claims, use the following commands:

kubectl get pv
kubectl get pvc

Enter fullscreen mode Exit fullscreen mode

Deleting a Persistent Volume Claim (PVC)
Remove a specific Persistent Volume Claim:

kubectl delete pvc <pvc-name>
Enter fullscreen mode Exit fullscreen mode

Deleting a Persistent Volume (PV)
Remove a specific Persistent Volume:

kubectl delete pv <pv-name>
Enter fullscreen mode Exit fullscreen mode

Important Properties to Remember
Defining Volumes in Pod Specification:

##yaml

spec:
  volumes:
  - name: <volume-name>
    emptyDir: {}
Enter fullscreen mode Exit fullscreen mode

Mounting Volumes in Container Specification:

##yaml

spec:
  containers:
  - name: <container-name>
    volumeMounts:
    - name: <volume-name>
      mountPath: <path-in-container>
Enter fullscreen mode Exit fullscreen mode

HostPath Volume:

yaml
spec:
  volumes:
  - name: <volume-name>
    hostPath:
      type: Directory
      path: <host-path>
Enter fullscreen mode Exit fullscreen mode

Persistent Volume (PV) and Persistent Volume Claim (PVC) Relationship:
PVC remains in a pending state until bound to a PV.
StorageClassName and AccessModes must match between PV and PVC.
Storage size must be within the specified range.
Reclaim Policy for Persistent Volumes
Persistent Volumes have a reclaim policy that dictates their future when the Persistent Volume Claim is deleted:

Recycle: Data in the volume is purged.
Retain: Both data and volume are retained.
Delete: Volume is deleted.
Specifying Reclaim Policy:

yaml

spec:
  persistentVolumeReclaimPolicy: <policy>
Enter fullscreen mode Exit fullscreen mode

PV and PVC Selection
PVs use labels, and PVCs use selectors for PV selection.
PVs are cluster-wide, while PVCs are namespaced.
Explore the world of Persistent Volumes and Claims to provide durable storage for your Kubernetes applications.

Happy Kuberneting!

💖 💪 🙅 🚩
mesrar
Mesrar

Posted on February 1, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related