0
0
Kubernetesdevops~30 mins

Volumes vs Persistent Volumes in Kubernetes - Hands-On Comparison

Choose your learning style9 modes available
Understanding Volumes vs Persistent Volumes in Kubernetes
📖 Scenario: You are working on a Kubernetes cluster where you need to store data generated by your applications. You want to understand the difference between simple Volumes and Persistent Volumes (PV) to manage data storage effectively.
🎯 Goal: Build a simple Kubernetes setup that defines a Pod using a basic Volume and then extend it to use a Persistent Volume and Persistent Volume Claim (PVC). This will help you see how data storage works in Kubernetes and the difference between ephemeral and persistent storage.
📋 What You'll Learn
Create a Pod manifest with an emptyDir Volume
Add a Persistent Volume manifest with specific storage capacity
Create a Persistent Volume Claim manifest to request storage
Modify the Pod manifest to use the Persistent Volume Claim
Print the Pod specification to verify the volume configuration
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, applications often need to store data that outlives the Pod lifecycle. Understanding Volumes and Persistent Volumes helps manage data persistence and sharing.
💼 Career
DevOps engineers and Kubernetes administrators must know how to configure storage correctly to ensure application data durability and availability.
Progress0 / 4 steps
1
Create a Pod with an emptyDir Volume
Create a Kubernetes Pod manifest named pod.yaml with a Pod called my-pod. Inside the Pod spec, add a container named app-container using the image nginx. Add a Volume named temp-storage of type emptyDir. Mount this volume inside the container at /usr/share/nginx/html.
Kubernetes
Need a hint?

Use emptyDir: {} under volumes to create a temporary storage volume.

2
Define a Persistent Volume with storage capacity
Create a Persistent Volume manifest named pv.yaml with kind PersistentVolume. Name it pv-storage. Set the storage capacity to 1Gi under spec.capacity.storage. Use hostPath with path /mnt/data as the volume source. Set the access mode to ReadWriteOnce.
Kubernetes
Need a hint?

Use hostPath to simulate persistent storage on the node.

3
Create a Persistent Volume Claim and update Pod to use it
Create a Persistent Volume Claim manifest named pvc.yaml with kind PersistentVolumeClaim. Name it pvc-storage. Request 1Gi storage with access mode ReadWriteOnce. Then, update the Pod manifest to remove the emptyDir volume and instead use a volume named persistent-storage that references the claim pvc-storage. Mount this volume inside the container at /usr/share/nginx/html.
Kubernetes
Need a hint?

Use persistentVolumeClaim.claimName in the Pod volume to link the PVC.

4
Print the final Pod manifest to verify volume usage
Print the complete Pod manifest named my-pod to verify it uses the Persistent Volume Claim volume named persistent-storage mounted at /usr/share/nginx/html.
Kubernetes
Need a hint?

Use kubectl get pod my-pod -o yaml to print the Pod manifest.