当前位置:网站首页>CBS type PVC recycling strategy

CBS type PVC recycling strategy

2022-07-19 13:51:00 Chenjingwei

StorageClass The recycling strategy is reclaimPolicy: Delete

1, Static creation PV, Don't specify 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

establish PVC When , Also need not specify StorageClass To choose this pv, If specified, you cannot select this pv( The tip is : At present PersistentVolume And PersistentVolumeClaim As specified by the StorageClass atypism )

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: cbs-pvc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: ""
  volumeMode: Filesystem
  volumeName: cbs-pv
  

Delete PVC and PV When , Corresponding CBS The disk will not be recycled and deleted

2, Static creation PV, Appoint 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

establish PVC, You need to select the corresponding 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

Simulate creating a file of a certain size : dd if=/dev/zero of=hello.txt bs=100M count=1 Delete PVC and PV When , Corresponding CBS The disk will not be recycled and deleted

3, Dynamically create pvc , Don't specify pv, Automatically created pv

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: cbs-pvc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: cbs

Be careful : because cbs Recovery strategy yes Delete , So delete pvc When , Corresponding PV and CBS The disk will also be deleted automatically

StorageClass The recycling strategy is reclaimPolicy: Retain

4, Dynamically create PVC, Retention policy

1) establish reclaimPolicy: Retain Type of storgeclass and 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) Then delete the corresponding PVC, And the corresponding PV It didn't delete ,PV Status is Released

[[email protected] ~]# 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) Delete separately PV When , Corresponding CBS The disk will not be deleted

[[email protected] ~]# kubectl  delete pv pvc-ae7a89e4-3a3c-4f87-b0c9-fffaf91559d2
persistentvolume "pvc-ae7a89e4-3a3c-4f87-b0c9-fffaf91559d2" deleted
picture .png

4) Modify corresponding PV To configure , Delete spec.claimRef part , Corresponding PV Can be with other pvc binding

picture .png
原网站

版权声明
本文为[Chenjingwei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207171904030748.html