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: pv-todo-app
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/tmp/data"
Apply the updates using command kubectl apply -f pv.yaml
- Create a Persistent Volume Claim that references the Persistent volume.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-todo-app
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
Apply the updates using command kubectl apply -f pvc.yaml
- Update your deployment.yml file to include the Persistent Volume Claim. After Applying pv.yml pvc.yml your deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
name: node-todo-app
namespace: node-app-deployment
labels:
app: node-app
spec:
replicas: 3
selector:
matchLabels:
app: node-app
template:
metadata:
labels:
app: node-app
spec:
containers:
- name : node-app
image: sarikak/node-app-batch-6
ports:
- containerPort: 8000
volumeMounts:
- name: todo-app-data
mountPath: /app
volumes:
- name: todo-app-data
persistentVolumeClaim:
claimName: pvc-todo-app
- 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 commands
kubectl get pods
,kubectl get pv
✒️Task 2:
- Connect to a Pod in your Deployment using command : `kubectl exec -it -- /bin/bash
- Verify that you can access the data stored in the Persistent Volume from within the Pod
📚Happy Learning :)