Use Persistent Volume (PV) and Persistent Volume Claim (PVC) with VNG Cloud
PersistentVolume(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.
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2Fdocs.vngcloud.vn%2Fdownload%2Fattachments%2F59802536%2Fimage2023-4-26_13-12-34.png%3Fversion%3D1%26modificationDate%3D1684996043000%26api%3Dv2&width=768&dpr=4&quality=100&sign=c9d69afa&sv=1)
Step 1: Create PersistentVolume(PV) and PersistentVolumeClaim(PVC)
1. Prepare yaml file to create PV and PVC
nginx-pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gold
2. Create PV and PVC
# kubectl apply -f nginx-pvc.yaml
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2Fdocs.vngcloud.vn%2Fdownload%2Fattachments%2F59802536%2Fimage2023-4-26_13-34-33.png%3Fversion%3D1%26modificationDate%3D1684996343000%26api%3Dv2&width=768&dpr=4&quality=100&sign=49aea7a&sv=1)
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2Fdocs.vngcloud.vn%2Fdownload%2Fattachments%2F59802536%2Fimage2023-4-26_13-35-23.png%3Fversion%3D1%26modificationDate%3D1684996343000%26api%3Dv2&width=768&dpr=4&quality=100&sign=9fa4684e&sv=1)
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
3. Check on VNG Cloud portal
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2Fdocs.vngcloud.vn%2Fdownload%2Fattachments%2F59802536%2Fimage2023-4-26_13-24-47.png%3Fversion%3D1%26modificationDate%3D1684996553000%26api%3Dv2&width=768&dpr=4&quality=100&sign=a782c253&sv=1)
Step 2: Use PersistentVolumeClaim
1. Prepare yaml file to use PVC:
web-deployment.yaml
---
|
2. Application Deployment
# kubectl apply -f web-deployment.yaml
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2Fdocs.vngcloud.vn%2Fdownload%2Fattachments%2F59802536%2Fimage2023-4-26_13-37-26.png%3Fversion%3D1%26modificationDate%3D1684997603000%26api%3Dv2&width=768&dpr=4&quality=100&sign=493fcb6b&sv=1)
![](https://docs.vngcloud.vn/~gitbook/image?url=https%3A%2F%2Fdocs.vngcloud.vn%2Fdownload%2Fattachments%2F59802536%2Fimage2023-4-26_13-37-15.png%3Fversion%3D1%26modificationDate%3D1684997663000%26api%3Dv2&width=768&dpr=4&quality=100&sign=a21314db&sv=1)
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.
Step 3: Remove PersistentVolume and PersistentVolumeClaim
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
Last updated