Table of contents
What are Persistent Volumes in k8s?
In Kubernetes, a Persistent Volume (PV) is a piece of storage in the cluster that has been provisioned by an administrator. A Persistent Volume Claim (PVC) is a request for storage by a user. The PVC references the PV, and the PV is bound to a specific node.
Read official documentation of Persistent Volumes.
Task 01
Add a Persistent Volume to your Deployment todo app.
Create a Persistent Volume using a file on your node. Template
Create a Persistent Volume Claim that references the Persistent Volume. Template
Update your deployment.yml file to include the Persistent Volume Claim. After Applying pv.yml pvc.yml your deployment file looks like this template
Apply the updated deployment using the command:
kubectl apply -f deployment.yml
Verify that the Persistent Volume has been added to your Deployment by checking the status of the Pods and Persistent Volumes in your cluster. Use this commands
kubectl get pods
,kubectl get pv
[⚠️ Don't forget: To apply changes or create files in your Kubernetes deployments, each file must be applied separately. ⚠️]
Pre-requisite: Create a new AWS EBS volume
and make sure availability zones must be matched with minikube installed machine availability zone.
AWS EBS volume will be available after some time.
Let's start our task now.
Step 1: Create a Persistent Volume
file on the node.
Step 2: Create a Persistent Volume Claim
file that references the "Persistent Volume".
Step 3: Either update the deployment
file or create a new one that includes a "Persistent Volume Claim".
Step 4: Verify the Persistent Volume added to the deployment file as shown in image.
Task 02
Accessing data in the Persistent Volume,
Connect to a Pod in your Deployment using the command:
kubectl exec -it -- /bin/bash
Verify that you can access the data stored in the Persistent Volume from within the Pod.
Step 1: Connect to anyone Pod in the deployment using the command Kubectl exec -it <pod-name> -n <namespace> -- /bin/bash
and create some data inside it.
Step 2: For verification purpose, delete the pod by using the command kubectl delete pod <pod-name> -n <namespace>
Checking the pod status, the deleted pod will be retained with a new name.
Again try to get inside the new pod and check whether the created data is available there or not.
Thus we have accomplished our data retainment process via PersistentVolume successfully.
Happy learning guys.
Reference: Check out this video for understanding this task.
Thanks for reading the articles.
Keep upskilling and motivated.
Stay tuned for the new-Blogs.
Peace out!!