Skip to main content

🌐 Kubernetes Storage – Persistent Volumes and StorageClasses

 

Kubernetes Storage – Persistent Volumes and StorageClasses

Kubernetes provides a powerful storage system to ensure data persistence for containerized applications. Since Pods are ephemeral and can be deleted or restarted anytime, Kubernetes uses Persistent Volumes (PV) and Persistent Volume Claims (PVC) to manage storage efficiently.


🌍 Shape Your Future with AI & Infinite Knowledge...!!

🌐 Want to Generate Text-to-Voice, Images & Videos? 👉 http://www.ai.skyinfinitetech.com 📚 Read In-Depth Tech & Self-Improvement Blogs 👉 http://www.skyinfinitetech.com ▶ Watch Life-Changing Videos on YouTube 👉 https://www.youtube.com/@SkyInfinite-Learning 🔥 Transform Your Skills, Business & Productivity – Join Us Today! 🔥



🔌 Understanding Kubernetes Storage

Ephemeral Storage – Data stored inside a Pod is lost when the Pod is deleted.
Persistent Storage – Data remains even if the Pod is restarted or moved.
Persistent Volumes (PV) – A storage resource provisioned in the cluster.
Persistent Volume Claims (PVC) – A request from a Pod to use a PV.
StorageClass – Defines different types of storage (e.g., SSD, HDD, cloud storage).



🏗 Key Kubernetes Storage Concepts

1️⃣ Ephemeral Storage – Pod-Level Storage

Kubernetes provides emptyDir and hostPath for temporary storage.

🔹 emptyDir – Temporary Storage Inside Pods

  • Deleted when the Pod is removed.
  • Useful for caching or temporary files.
yaml

apiVersion: v1 kind: Pod metadata: name: temp-storage-pod spec: containers: - name: busybox image: busybox command: [ "sleep", "3600" ] volumeMounts: - mountPath: "/cache" name: cache-volume volumes: - name: cache-volume emptyDir: {}


🔹 hostPath – Access Host System Storage

  • Used for accessing node’s file system.
  • Not recommended for multi-node clusters.
yaml

apiVersion: v1 kind: Pod metadata: name: host-storage-pod spec: containers: - name: busybox image: busybox command: [ "sleep", "3600" ] volumeMounts: - mountPath: "/data" name: host-volume volumes: - name: host-volume hostPath: path: "/mnt/data"


2️⃣ Persistent Volumes (PV) – Cluster-Level Storage

A Persistent Volume (PV) is a cluster-wide storage resource that provides storage to Pods. It supports multiple storage backends like NFS, AWS EBS, Azure Disks, GCE Persistent Disks, and more.

🔹 Creating a Persistent Volume (PV)

yaml

apiVersion: v1 kind: PersistentVolume metadata: name: my-pv spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: manual hostPath: path: "/mnt/k8s-data"

PV Access Modes:

Access ModeDescription
ReadWriteOnce (RWO)One node can read & write.
ReadOnlyMany (ROX)Multiple nodes can read.
ReadWriteMany (RWX)Multiple nodes can read & write.


3️⃣ Persistent Volume Claims (PVC) – Requesting Storage

A Persistent Volume Claim (PVC) is a request for storage from a Persistent Volume (PV).

🔹 Creating a Persistent Volume Claim (PVC)

yaml

apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi storageClassName: manual


🔹 Using a PVC in a Pod

yaml

apiVersion: v1 kind: Pod metadata: name: my-pvc-pod spec: containers: - name: busybox image: busybox command: [ "sleep", "3600" ] volumeMounts: - mountPath: "/data" name: storage volumes: - name: storage persistentVolumeClaim: claimName: my-pvc


4️⃣ StorageClass – Dynamic Storage Provisioning

Instead of manually creating PVs, StorageClasses allow dynamic volume provisioning.

🔹 Creating a StorageClass for AWS EBS

yaml

apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: aws-ebs provisioner: kubernetes.io/aws-ebs parameters: type: gp2 fsType: ext4


🔹 Creating a PVC That Uses StorageClass

yaml

apiVersion: v1 kind: PersistentVolumeClaim metadata: name: dynamic-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: aws-ebs

📌 When this PVC is created, Kubernetes will automatically provision an AWS EBS volume.



🔄 Troubleshooting Kubernetes Storage

🔹 Check Persistent Volumes (PV)


kubectl get pv kubectl describe pv my-pv


🔹 Check Persistent Volume Claims (PVC)


kubectl get pvc kubectl describe pvc my-pvc


🔹 Check StorageClasses


kubectl get storageclass kubectl describe storageclass aws-ebs


🏆 Summary – Kubernetes Storage at a Glance

ConceptPurpose
emptyDirTemporary storage for a Pod (deleted when Pod stops).
hostPathAccesses node’s storage (tied to specific node).
Persistent Volume (PV)Pre-provisioned cluster-wide storage resource.
Persistent Volume Claim (PVC)Request for storage from a PV.
StorageClassEnables dynamic storage provisioning.

📢 Next Up: Kubernetes Deployments – Scaling and Rolling Updates with ReplicaSets!

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...