Day 36: Managing Persistent Volumes in Your Deployment ??

Day 36: Managing Persistent Volumes in Your Deployment ??

?? Kudos to you for conquering ConfigMaps and Secrets yesterday! Today, we take it a step further with Persistent Volumes in Kubernetes.


What Are Persistent Volumes (PVs)?

A Persistent Volume (PV) is storage provisioned by an admin in the Kubernetes cluster, while a Persistent Volume Claim (PVC) is a user's request for that storage. Together, they enable storage management for stateful applications.


Today's Tasks

Task 1: Add a Persistent Volume to Your Deployment

  1. Create a Persistent Volume (PV): Use a file (pv.yml) to define the storage on your node. Example template:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: todo-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/todo        

Create a Persistent Volume Claim (PVC): Define a claim in pvc.yml to use the storage.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: todo-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi        

Update your deployment.yml: Add the PVC to your pod specification. Example:

volumes:
  - name: todo-storage
    persistentVolumeClaim:
      claimName: todo-pvc
containers:
  - name: todo-app
    volumeMounts:
      - mountPath: "/app/data"
        name: todo-storage        

Apply the files:

kubectl apply -f pv.yml
kubectl apply -f pvc.yml
kubectl apply -f deployment.yml        

Verify the PV and PVC:

kubectl get pv
kubectl get pvc
kubectl get pods        

Task 2: Access Data in the Persistent Volume

  1. Connect to a Pod in Your Deployment:

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

2. Verify Data Accessibility: Check if you can access and modify the data in the mounted volume.


Wrap-Up

Persistent Volumes enable stateful applications in Kubernetes by providing reliable storage. Practice these tasks to solidify your skills! ??

#day36 #KubernetesStorage #PersistentVolumes #DevOpsJourney #90DaysOfDevOps #StatefulApplications


要查看或添加评论,请登录

Akshay Ghalme的更多文章

社区洞察

其他会员也浏览了