Creating and Attaching Persistent Storage in Kubernetes
In this blog post, we will walk through the step to create Persistent Volume (PV) and a Persistent Volume Claim (PVC) in Kubernetes, and then attaching them to a Deployment so that we can mount host path to the path of containers running. It is essential for applications that require persistent storage.
Persistent Volume (PV):
A Persistent Volume (PV) is a piece of storage that has been mounted either on host path of cluster or either has been mounted on any cloud services like Amazon EBS (Elastic Block Store). It is independent of any individual pod that uses the PV, it means it persists even when a pod is deleted, we can use this PV for other pods to use.
Persistent Volume Claim (PVC):
A Persistent Volume Claim (PVC) is a type claim or request for storage by user. It is similar to a pod in pods which consume node resources similarly PVCs consume PV resources. We know that pods can request CPU and Memory similarly PVCs can request specific sizes and access modes( RWX, RWO, ROX).
Steps to create PV, PVC and attaching it to deployments.
Step-1: Creating a Persistent Volume (PV)
For creating PV, we need to create pv.yaml file and type below code.
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
Here we have attached "/mnt/data" as a path on host
Subscribe to my newsletter
Read articles from Gaurav Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gaurav Kumar
Gaurav Kumar
I am working as a full time DevOps Engineer at Tata Consultancy Services from past 2.7 yrs, I have very good experience of containerization tools Docker, Kubernetes, OpenShift. I have good experience of using Ansible, Terraform and others.