Day36:Managing Persistent Volumes in Your Deployment
Day 36: #90DaysOfDevOpsChallenge
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.
Task 1:
Add a Persistent Volume to your Deployment todo app.
Create a Persistent Volume using a file on your node.
This is a piece of storage in your cluster that can be dynamically provisioned and claimed by a Pod. To create a Persistent Volume, you can use a file on your node. You can create a YAML file, called pv.yml, that defines the Persistent Volume. This file should include the size of the storage, the access modes, and the path to the file on your node.
Apply the updates using command kubectl apply -f pv.yaml
Create a Persistent Volume Claim that references the Persistent Volume.
A Persistent Volume Claim is a request for storage by a user. It specifies the required size and access modes of the storage, and is automatically bound to a matching Persistent Volume. You can create a YAML file, called pvc.yml, that defines the Persistent Volume Claim.
Apply the updates using command kubectl apply -f pvc.yaml
Update your deployment.yml file to include the Persistent Volume Claim.
To use the Persistent Volume Claim in your Deployment, you need to update your Deployment file, deployment.yml. You should add a volume and a volumeMount section to the container definition, which references the Persistent Volume Claim.
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
These commands will show the list of Pods and Persistent Volumes in your cluster.
Task 2:
Accessing data in the Persistent Volume,
Connect to a Pod in your Deployment using command : `kubectl exec -it pod-name -- /bin/bash
below inside the /tmp/data folder create a new file named testfile.txt
kubectl exec -it todo-app-deployment-844d49d6b9-npc5s -- /bin/bash (Oldpod)
Verify that you can access the data stored in the Persistent Volume from within the Pod
delete a pod which we used in above step and create a new pod using command kubectl apply -f deployment.yaml
kubectl exec -it todo-app-deployment-844d49d6b9-2hfs7 -- /bin/sh (NewPod)
Go inside a pod using kubectl exec command, then go to the folder and check testfile.txt file.
Thank you for reading!! Hope you find this helpful.
#day36challenge#90daysofdevops
Always open to suggestions..!!
~ Manoj Bhamidipati ๐