DEV Community

Cover image for What is Persistent Volume (PV) & Persistent Volume Claim (PVC) in Kubernetes?
Sagar Jadhav
Sagar Jadhav

Posted on • Originally published at developersthought.in

What is Persistent Volume (PV) & Persistent Volume Claim (PVC) in Kubernetes?

Here, I am covering concepts of persistent volume (PV) & persistent volume claim (PVC). In the previous blog I have covered how to deploy PHPMyAdmin application in kubernetes. PHPMyAdmin application does not have a persistent storage. Hence If MySQL pod die due to some unexpected error for e.g. resource crunch then data stored in database will also get deleted as data by default stored in pod. Pods by default are stateless in nature. Hence to persist MySQL data PV & PVC is required.

Persistent Volume (PV)

Storage provisioned by administrator. Learn more here

Persistent Volume Clain (PVC)

Request for a storage by user. Learn more here

Architecture

Architecture

Prerequisites:

Deploy PHPMyAdmin Application

Follow Deploy phpMyAdmin application on kubernetes blog

Go to session_2 directory

cd ../session_2/
Enter fullscreen mode Exit fullscreen mode

Step 1: Create NFS share

Reference:

I have created NFS mount at /mnt/share location on VM with IP 192.168.1.6

Step 2: Create Persistent Volume (PV)

kubectl create -f db-pv.yaml
Enter fullscreen mode Exit fullscreen mode

Step 3: Create Persistent Volume Claim (PVC)

kubectl create -f db-pvc.yaml
Enter fullscreen mode Exit fullscreen mode

Step 4: List PV & PVC

kubectl get pvc
Enter fullscreen mode Exit fullscreen mode
kubectl get pv
Enter fullscreen mode Exit fullscreen mode

Step 5: Redeploy MySQL deployment

kubectl delete deployment db
Enter fullscreen mode Exit fullscreen mode
kubectl create -f db-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Here db-deployment.yaml is updated YAML with volume & volume mounts. Next watch pods.

kubectl get pods -n watch
Enter fullscreen mode Exit fullscreen mode

Exit once db pod goes into running state.

Step 6: Go to mount directory and list files

cd /mnt/share
Enter fullscreen mode Exit fullscreen mode
ls -ltr
Enter fullscreen mode Exit fullscreen mode

Demo

Discussion (0)