Skip to main content

Command Palette

Search for a command to run...

Demystifying Persistent Volumes in Kubernetes: A Simple Guide Day - 36

Published
โ€ข2 min read
V

๐Ÿ‘‹ Hello, I'm Vishal, an aspiring Information Technology enthusiast currently embarking on a journey towards a Bachelor's degree in Engineering. My passion lies in exploring the dynamic realms of cloud computing and DevOps technologies, where I constantly strive to bridge the gap between innovation and practical implementation.

๐Ÿ’ก As a student of Information Technology, I'm on a mission to absorb knowledge, solve real-world problems, and contribute to the tech community. My academic pursuits fuel my curiosity, and my hands-on experience with cloud and DevOps tools empowers me to navigate the evolving landscape of modern technology.

๐Ÿš€ Join me as I share insights, discoveries, and challenges encountered on this exciting educational and professional adventure. Let's connect, collaborate, and grow together in the ever-expanding world of IT.

๐Ÿ”— Connect with me on social media and let's build a network that fosters learning, sharing, and innovation.

Happy coding! ๐ŸŒŸ

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! ๐Ÿง™โ€โ™‚๏ธ๐Ÿš€

More from this blog

Untitled Publication

81 posts