Day 36 Task: Managing Persistent Volumes in Your Deployment π₯
#90dayasofdevopschallenge
Table of contents
- π Task-1 Create a Persistent Volume using a file on your node
- π Update your deployment.yml file to include the Persistent Volume Claim.
- π After Applying pv.yml pvc.yml your deployment file look like this Template Apply the updated deployment using the command: kubectl apply -f deployment.yml
- π 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 command kubectl get pods ,
- π Task -2 Accessing data in the Persistent Volume, Connect to a Pod in your Deployment using command : `kubectl exec -it -- /bin/bash
- Thank You
π 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 (PVC) is a request for storage by a user. The PVC references the PV, and the PV is bound to a specific node.
π Task-1 Create a Persistent Volume using a file on your node
Create a Persistent Volume Claim that references the Persistent Volume.
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv
namespace: todo
spec:
capacity:
storage: 2Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/home/ubuntu/pvvolume"
Add the persistent volume claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
namespace: todo
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
π Update your deployment.yml file to include the Persistent Volume Claim.
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-deployment
namespace: todo
labels:
app: todo-app
spec:
replicas: 3
selector:
matchLabels:
app: todo-app
template:
metadata:
labels:
app: todo-app
spec:
containers:
- name: todo-app
image: trainwithshubham/django-todo:latest
ports:
- containerPort: 8000
volumeMounts:
- name: pvcdata
mountPath: /test
volumes:
- name: pvcdata
persistentVolumeClaim:
claimName: mypvc
π After Applying pv.yml pvc.yml your deployment file look like this Template Apply the updated deployment using the command: kubectl apply -f deployment.yml
π 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 command kubectl get pods ,
π Task -2 Accessing data in the Persistent Volume, Connect to a Pod in your Deployment using command : `kubectl exec -it -- /bin/bash
Thank You
Β