Day 36 Task: Managing Persistent Volumes in Your Deployment

Day 36 Task: Managing Persistent Volumes in Your Deployment

Devops Engineers, In previous article we will learn Configmaps & Secrets, In today we will learn Persistent Volumes & Claims.

What are Persistent Volumes in K8s?

In kubernetes a Persistent volume (PV) is a piece of Storage in the cluster that has been provisioned by an administrator. A Persistent Volume claim is a request for storage by a user, The PVC refernce the PV, and the PV is bound to a specfic node.

Now let's discuss with the help of tasks

Today's tasks:

Task 1:

Add a Persistent Volume to your Deployment todo app.

Create a Persistent Volume using a file on your node.

This is a piece of storage in your cluster that can be dynamically provisioned and claimed by a Pod, To create a Persistent Volume you can use a file on your node. You can create a YAML file, called pv.yaml, that defines the Persistent Volume.

Follow the Steps for task;-

1 Login AWS Account and access with the help of Ssh.

2 start minikube.

3 Create a pv.yaml file & enter all the code in it.

4 save with help of pv.yaml file & enter all the code in it.

4 save with help of CTRL+s command.

5 Copy the pv.yaml file syntax from kubernetes offical website.

kubernetes.io/docs/tasks/configure-pod-cont..

No alt text provided for this image

Copy the pv.yaml file syntax from kubernetes offical website. Diagram.

Apply the updates using command.

Syntax:- kubectl apply -f pv.yaml

No alt text provided for this image

Syntax:- kubectl apply -f pv.yaml Digram.

Create a Persistent volume claim that reference that Persistent Volume.

A Persistent volume is a request for storage by a user. it specifies the required size and access modes of the storage and is automatically bound to a matching Persistent Volume. You can create a YAML file, called pvc.yaml,that defines the Persistent volume claim.

No alt text provided for this image

pvc.yaml file.

I will use the syntax form these link:-

kubernetes.io/docs/concepts/storage/persist..

Apply the updates using command kubectl -f ally pvc.yaml.

No alt text provided for this image

No alt text provided for this image

kubectl -f ally pvc.yaml Diagram.

To use the Persistent volume claim in your deployment,you need to update your Deployment file. deployment.yml. you should add a volume and a volume Mount section to the containers definition,which reference the Persistent Volume Claim.

No alt text provided for this image

Deployment.yaml file Diagram.

No alt text provided for this image

cat Deployment.yaml file diagram.

Apply the updated deployment using the command:-

Syntax: kubectl apply -f deployment.yaml

Verify that the Persistent Volume has been added to your Deployment by checking the status of the Pods and Persistent Volumes in your cluster. Use this commands

Syntax:- kubectl get pods

kubectl get pv

No alt text provided for this image

Task 2:

Access data in the Persistent Volume,

Connect to a Pod in your Deployment using command:

Syntax: kubectl exec -it pod-name --/bin/bash

below inside app folder create a new file named demo.txt

No alt text provided for this image

kubectl exec -it pod-name --/bin/bash

That's all for today

Thank you for Reading !! Stay Connected