Demystifying Persistent Volumes in Kubernetes: A Simple Guide Day - 36
Welcome, DevOps Explorers!
In today's #90daysofDevOps adventure, we're tackling a vital topic in Kubernetes – Persistent Volumes (PV). Fear not, we're keeping it simple and fun! If you haven't already, share your thoughts on the challenge here. Your feedback powers our growth.
Persistent Volumes 101
In Kubernetes lingo, a Persistent Volume (PV) is like your very own storage slice in the cluster. It's managed by the admin. A Persistent Volume Claim (PVC) is your way of saying, "Hey, I need some storage." Think of it like ordering a pizza – you make the request, and the pizza (storage) arrives at your door.
Now, let's dive into today's tasks!
Task 1: Adding a Storage Boost to your Deployment
Step 1: Craft a Persistent Volume (pv.yml)
Create a file named pv.yml
with this magic spell:
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /path/on/your/node
This YAML sets up your storage wishes – size, access mode, and where it should appear on your node.
Step 2: Summon a Persistent Volume Claim (pvc.yml)
Create pvc.yml
with this charm:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
This YAML is your way of saying, "I claim this storage!" Specify your storage size in the requests
section.
Step 3: Update Your Deployment (deployment.yml)
Sprinkle some magic into your deployment YAML. Update volumes
and volumeMounts
:
...
spec:
containers:
- name: your-container-name
image: your-image
volumeMounts:
- name: my-persistent-storage
mountPath: /path/in/container
volumes:
- name: my-persistent-storage
persistentVolumeClaim:
claimName: my-pvc
...
Make sure your deployment knows about the storage by updating these sections.
Step 4: Cast the Spell!
Apply the changes:
kubectl apply -f pv.yml
kubectl apply -f pvc.yml
kubectl apply -f deployment.yml
Step 5: Check the Crystal Ball
Verify your spells worked:
kubectl get pods
kubectl get pv
Task 2: Peek into the Magic Storage
Step 1: Open the Door to a Pod
Use this command to step inside your pod:
kubectl exec -it <pod-name> -- /bin/bash
Step 2: Check Out the Magic Storage
Navigate to your container's secret storage spot:
ls /path/in/container
cat /path/in/container/your-file.txt
Ta-da! You've added magic storage to your deployment and peeked inside. Stay tuned for more adventures in the world of DevOps. Keep the magic alive, wizards of the cloud! 🧙♂️🚀