Day 36: Managing Persistent Volumes in Your Deployment ??
Akshay Ghalme
DevOps Engineer Helping Organisations with DevOps Solutions | AWS | Jenkins | CI/CD | Docker | Ansible | terraform | Kubernetes
?? Kudos to you for conquering ConfigMaps and Secrets yesterday! Today, we take it a step further with Persistent Volumes in Kubernetes.
What Are Persistent Volumes (PVs)?
A Persistent Volume (PV) is storage provisioned by an admin in the Kubernetes cluster, while a Persistent Volume Claim (PVC) is a user's request for that storage. Together, they enable storage management for stateful applications.
Today's Tasks
Task 1: Add a Persistent Volume to Your Deployment
apiVersion: v1
kind: PersistentVolume
metadata:
name: todo-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/todo
Create a Persistent Volume Claim (PVC): Define a claim in pvc.yml to use the storage.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: todo-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Update your deployment.yml: Add the PVC to your pod specification. Example:
volumes:
- name: todo-storage
persistentVolumeClaim:
claimName: todo-pvc
containers:
- name: todo-app
volumeMounts:
- mountPath: "/app/data"
name: todo-storage
领英推荐
Apply the files:
kubectl apply -f pv.yml
kubectl apply -f pvc.yml
kubectl apply -f deployment.yml
Verify the PV and PVC:
kubectl get pv
kubectl get pvc
kubectl get pods
Task 2: Access Data in the Persistent Volume
kubectl exec -it <pod-name> -- /bin/bash
2. Verify Data Accessibility: Check if you can access and modify the data in the mounted volume.
Wrap-Up
Persistent Volumes enable stateful applications in Kubernetes by providing reliable storage. Practice these tasks to solidify your skills! ??
#day36 #KubernetesStorage #PersistentVolumes #DevOpsJourney #90DaysOfDevOps #StatefulApplications