Persistent Volumes in k8s:-
In Kubernetes (k8s), a Persistent Volume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. Persistent Volumes are used to store data in a way that it persists beyond the lifecycle of a pod. This allows data to be retained even if the pod is terminated or rescheduled.
Here are some key concepts related to Persistent Volumes in Kubernetes:
Persistent Volume (PV): This is a cluster-wide resource that represents a piece of storage in the cluster. PVs are provisioned by administrators manually or dynamically by Storage Classes.
Persistent Volume Claim (PVC): This is a request for storage by a user. It is used by a pod to claim a specific amount of storage from a PV. PVCs are bound to PVs, and the actual storage is provisioned dynamically based on the Storage Class or statically if the PV is pre-provisioned.
Storage Class: A Storage Class is used by administrators to define different "classes" of storage in a Kubernetes cluster. Storage Classes enable dynamic provisioning of Persistent Volumes.
Here is a basic example of how Persistent Volumes work:
yamlCopy codeapiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
---
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: example-container
image: nginx
volumeMounts:
- name: data-volume
mountPath: "/usr/share/nginx/html"
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: example-pvc
In this example:
A Persistent Volume (
example-pv
) is defined with a capacity of 5Gi, using ahostPath
as the storage backend.A Persistent Volume Claim (
example-pvc
) requests 3Gi of storage with the access mode ReadWriteOnce.A Pod (
example-pod
) is defined as a container that mounts the Persistent Volume Claim as a volume.
Today's Task:-
Create a Persistent Volume using a file on your node.
Create a Persistent Volume Claim that references the Persistent Volume.
Update your deployment.yml file to include the Persistent Volume Claim. After Applying pv.yml pvc.yml your deployment file looks like this Template.
Apply the updated deployment using the command:
kubectl apply -f deployment.yml
Day 36 of #90daysofDevOps
Thanks for reading
Follow me for more about DevOps♾️........
________________________________________________________________________________
#90daysHardChallenge
#Cloudcomputing
#DevOps
#Python
#TrainWithShubham