Persistent Volumes & Persistent Volume Claim (PV & PVC)
A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes.
It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV.
This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.
Step 1 : Create a Persistent Volume (PV)
- Create a YAML file named
pv.yml
,
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
- Apply,
kubectl apply -f pv.yml
Step 2 : Create a Persistent Volume Claim (PVC)
- Create a YAML file named
pvc.yml
,
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
- Apply,
kubectl apply -f pvc.yml
Step 3 : Use the PVC in a Pod
- Create a YAML file named
pod.yml
,
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: my-storage
volumes:
- name: my-storage
persistentVolumeClaim:
claimName: my-pvc
Connect With Me
Thank you for reading. I hope you were able to understand and learn something new from my blog.
Happy Learning!