Day 36- Mastering Persistent Volumes in Your Kubernetes Deployment ππΎ (Jan 01, 2024)

Introduction:
Congratulations on reaching Day 36 of the #90DaysOfDevOps Challenge! Yesterday, we delved into the realms of ConfigMaps and Secrets in Kubernetes, enhancing our understanding of managing configuration data and secrets securely. Today, our focus shifts to Persistent Volumes (PVs) and how they play a crucial role in managing storage in a Kubernetes cluster.
What are Persistent Volumes in Kubernetes?
In Kubernetes, a Persistent Volume (PV) represents a piece of storage provisioned by an administrator in the cluster. It acts as a storage resource that can be dynamically or statically provisioned. A Persistent Volume Claim (PVC), on the other hand, is a user's request for storage. The PVC references a PV, and once bound, the PV is associated with a specific node.
Task 1: Adding a Persistent Volume to Your Deployment
1. Create a Persistent Volume:
Create a Persistent Volume using a file on your node. Here's a template for pv.yml:
apiVersion: v1
kind: PersistentVolume
metadata:
name: todo-app-pv
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
hostPath:
path: "/your/local/path"
Replace /your/local/path with the desired local path on your node.
2. Create a Persistent Volume Claim:
Create a Persistent Volume Claim using a file. Here's a template for pvc.yml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: todo-app-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
3. Update Deployment YAML to Include the Persistent Volume Claim:
Modify your deployment.yml file to include the Persistent Volume Claim. Add the following snippet under spec.template.spec.containers:
volumeMounts:
- name: todo-app-storage
mountPath: "/path/in/container"
4. Apply the Updated Deployment:
Execute the following command to apply the updated deployment:
kubectl apply -f deployment.yml
5. Verify the Persistent Volume:
Check the status of Pods and Persistent Volumes:
kubectl get pods
kubectl get pv
Task 2: Accessing Data in the Persistent Volume
1. Connect to a Pod:
Use the following command to connect to a Pod in your Deployment:
kubectl exec -it <pod-name> -- /bin/bash
2. Verify Access to Data:
Inside the Pod, verify that you can access the data stored in the Persistent Volume.




