StorageClass回收策略是reclaimPolicy: Delete
1,静态创建PV, 不指定StorageClass
代码语言:txt复制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不一致 )
代码语言:txt复制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
代码语言:txt复制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
代码语言:txt复制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
代码语言:txt复制apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cbs-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: cbs
注意:由于cbs 回收策略 是 Delete ,所以删除pvc时候,对应的PV和CBS盘也会自动删除
StorageClass回收策略是reclaimPolicy: Retain
4,动态创建PVC,保留策略
1)创建reclaimPolicy: Retain 类型的storgeclass 和PVC
代码语言:txt复制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
代码语言:txt复制[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盘也是不会删除的
代码语言:txt复制[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绑定