# Day 35 Task: Managing Persistent Volumes in Your Deployment

## What are Persistent Volumes in k8s

# **<mark>Persistent Volumes</mark>**

A *PersistentVolume* (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using [Storage Classes](https://kubernetes.io/docs/concepts/storage/storage-classes/). It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.

# *<mark>PersistentVolumeClaim</mark>* <mark> (PVC)</mark>

A *PersistentVolumeClaim* (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., they can be mounted ReadWriteOnce, ReadOnlyMany, ReadWriteMany, or ReadWriteOncePod, see [AccessModes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)).

## **<mark>Lifecycle of a volume and claim</mark>**

PVs are resources in the cluster. PVCs are requests for those resources and also act as claim checks to the resource. The interaction between PVs and PVCs follows this lifecycle:

### **<mark>Provisioning</mark>**

There are two ways PVs may be provisioned: statically or dynamically.

### **<mark>Static</mark>**

A cluster administrator creates a number of PVs. They carry the details of the real storage, which is available for use by cluster users. They exist in the Kubernetes API and are available for consumption.

## **<mark>Dynamic</mark>**

When none of the static PVs the administrator created match a user's PersistentVolumeClaim, the cluster may try to dynamically provision a volume specially for the PVC. This provisioning is based on StorageClasses: the PVC must request a [storage class](https://kubernetes.io/docs/concepts/storage/storage-classes/) and the administrator must have created and configured that class for dynamic provisioning to occur. Claims that request the class `""` effectively disable dynamic provisioning for themselves.

### <mark>Task 1:</mark>

Add a Persistent Volume to your Deployment todo app.

1\. Create a Persistent Volume using a file on your node.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704044275587/de5fb302-db9e-4b11-b963-89ccfe67f81a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704044620368/f275b0ee-43b3-4712-a04d-e764a1bb998c.png align="center")

here can see how to create a persistent volume.

1. Create a Persistent Volume Claim.
    
    We have go to k8s culster and create pvc using template file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704045063412/8b561068-d357-4ecb-ac78-14ff8dca7edc.png align="center")
    
    with help file create a pvc.here we can see that how to create a pvc using the pvc.yml file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704045165597/6f778c4b-7a50-42c2-b7b1-8593ec03d57a.png align="center")
    
2. Update your deployment.yml file to include the Persistent Volume Claim. After Applying pv.yml pvc.yml your deployment file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704045825975/ae9f07ef-a9dc-4a2e-8998-9911a2067495.png align="center")
    
    here we can see that how to create a deployment file for appplicaytion and attached persistent volume and persistentvolume claim.
    
3. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704046022682/e4bcf88c-77f5-4738-8827-547c1309ef24.png align="center")
    

### <mark>Task 2:</mark>

* Connect to a Pod in your Deployment using command : \`kubectl exec -it -- /bin/bash
    
    Go to worker node then used it commmand for kubectl get pod.
    
* we can see that all continer run in worker node
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704046483972/d8b108fb-ce01-4cfb-bd2d-17b54671b84d.png align="center")
    
    *Thanks for read my blog if you liked it this blog please like and commend.*
    
    *Contact me on* [***linkedin***](http://www.linkedin.com/in/pradeep-chitroliya-9347a9147)
    
    *check out my GitHub for more resource* [***GitHub***](https://github.com/ChitrolyaPradeep)
