Use Persistent Volume (PV) and Persistent Volume Claim (PVC) with VNG Cloud
Last updated
Last updated
Address
VNG CorporationPersistentVolume(PV) is a part of the data storage space in the cluster, the PersistentVolume is the same as the normal Volume, but it exists independently of the POD (the pod deleted PV still exists), there are many types of PersistentVolume that can be deployed. like NFS, Clusterfs...
PersistentVolumeClaim(PVC) is required to use storage space (use PV). Visualize PV as Node, PVC as POD. POD running will use NODE's resources, PVC operation it uses PV's resources.
nginx-pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gold
# kubectl apply -f nginx-pvc.yaml
At this time, PV will automatically be created and will belong to StorageClass: csi-sc-cinderplugin-ssd because VNG Cloud is already defined with information of volume: SSD-IOPS-3000
web-deployment.yaml
---
apiVersion:
apps/v1 kind:
Deployment metadata:
name:
web-deployment spec:
replicas:
1 selector:
matchLabels:
app:
nginx template:
metadata:
labels:
app:
nginx spec:
volumes:
- name:
nginx-volume persistentVolumeClaim:
claimName:
nginx-pv readOnly:
false
containers:
- image:
nginx imagePullPolicy:
IfNotPresent name:
web-app ports:
- containerPort:
80 protocol:
TCP volumeMounts:
- mountPath:
/usr/share/nginx/html name:
nginx-volume
# kubectl apply -f web-deployment.yaml
3. Check:
Access the container and create the file:
# kubectl exec -it web-deployment-859679cc57-v8kw4 bash
4. Delete deployment
# kubectl delete -f web-deployment.yaml
5. Re-create deployment: this time the system will create new Pods, Containers # kubectl apply -f web-deployment.yaml
6. Access to the new container to check if the data on the PersistentVolume is lost # kubectl exec -it web-deployment-859679cc57-tglfg bash
=> As can be seen here, the data on the Persistent Volume is not lost.
When no longer need to use, customers can delete PV (Note need to delete resources that are using PVC before deleting PV): # kubectl delete -f nginx-pvc.yaml