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

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

sagarjadhv23 profile image Sagar Jadhav Originally published at developersthought.in ・2 min read

Kubernetes Primer (5 Part Series)

1) What is Deployment, Service, Secret and ConfigMap in Kubernetes? 2) What is Persistent Volume (PV) & Persistent Volume Claim (PVC) in Kubernetes? 3) What is Ingress Controller in Kubernetes? 4) What is Readiness & Liveness Probes in Kubernetes? 5) How to deploy applications using Helm 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/

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

Step 3: Create Persistent Volume Claim (PVC)

kubectl create -f db-pvc.yaml

Step 4: List PV & PVC

kubectl get pvc
kubectl get pv

Step 5: Redeploy MySQL deployment

kubectl delete deployment db
kubectl create -f db-deployment.yaml

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

kubectl get pods -n watch

Exit once db pod goes into running state.

Step 6: Go to mount directory and list files

cd /mnt/share
ls -ltr

Demo

Kubernetes Primer (5 Part Series)

1) What is Deployment, Service, Secret and ConfigMap in Kubernetes? 2) What is Persistent Volume (PV) & Persistent Volume Claim (PVC) in Kubernetes? 3) What is Ingress Controller in Kubernetes? 4) What is Readiness & Liveness Probes in Kubernetes? 5) How to deploy applications using Helm in Kubernetes?

Posted on Jun 6 by:

sagarjadhv23 profile

Sagar Jadhav

@sagarjadhv23

Backend Developer (Cloud ☁️) | Cloud Technology Enthusiast (🐳 ☸) Redhat Certified OpenShift Administrator

Discussion

markdown guide