1,静态创建PV, 不指定StorageClass
apiVersion: v1
kind: PersistentVolume
metadata:
name: cbs-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
csi:
driver: com.tencent.cloud.csi.cbs
volumeHandle: disk-h2v5jzxy
persistentVolumeReclaimPolicy: Retain
volumeMode: Filesystem
创建PVC时候,也需要不指定 StorageClass 才能选择到这个pv,如果使用指定了会无法选择这个pv(提示是: 当前PersistentVolume与PersistentVolumeClaim所指定的StorageClass不一致 )
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cbs-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: ""
volumeMode: Filesystem
volumeName: cbs-pv
删除PVC和PV时候,对应的CBS盘不会回收删除
2,静态创建PV, 指定StorageClass
apiVersion: v1
kind: PersistentVolume
metadata:
name: cbs-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
csi:
driver: com.tencent.cloud.csi.cbs
volumeHandle: disk-h2v5jzxy
persistentVolumeReclaimPolicy: Retain
storageClassName: cbs
volumeMode: Filesystem
创建PVC,需要选择对应的storageclass
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cbs-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: cbs
volumeMode: Filesystem
volumeName: cbs-pv
模拟创建一定大小文件 : dd if=/dev/zero of=hello.txt bs=100M count=1 删除PVC和PV时候,对应的CBS盘不会回收删除
3,动态创建pvc ,不指定pv,会自动创建pv
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cbs-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: cbs
注意:由于cbs 回收策略 是 Delete ,所以删除pvc时候,对应的PV和CBS盘也会自动删除
4,动态创建PVC,保留策略
1)创建reclaimPolicy: Retain 类型的storgeclass 和PVC
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: cbs-retain
parameters:
diskChargeType: POSTPAID_BY_HOUR
diskType: CLOUD_PREMIUM
provisioner: com.tencent.cloud.csi.cbs
reclaimPolicy: Retain
volumeBindingMode: Immediate
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cbs-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: cbs-retain
volumeMode: Filesystem
2)然后删除对应的PVC,而对应的PV并没有删除,PV状态是 Released
[root@VM-249-33-tlinux ~]# kubectl get pv,pvc
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-ae7a89e4-3a3c-4f87-b0c9-fffaf91559d2 10Gi RWO Retain Released default/cbs-pvc cbs-retain 2m47s
3)单独删除PV时候,对应的CBS盘也是不会删除的
[root@VM-249-33-tlinux ~]# kubectl delete pv pvc-ae7a89e4-3a3c-4f87-b0c9-fffaf91559d2
persistentvolume "pvc-ae7a89e4-3a3c-4f87-b0c9-fffaf91559d2" deleted
4)修改对应的PV配置,删除spec.claimRef部分,对应PV可以和其他pvc绑定
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。