PV recycling strategy
PersistentVolumes can have multiple recovery strategies, including the "Retain", "Recycle" and "Delete". For PersistentVolumes dynamically configured, the default recovery strategy "Delete". This means that when a user deletes the corresponding PersistentVolumeClaim, dynamic configuration of the volume will be automatically deleted. If the volume contains important data, this automatic behavior may be inappropriate. In that case, more suitable for "Retain" strategy. When using the "Retain", if a user deletes PersistentVolumeClaim, corresponding PersistentVolume will not be deleted. Instead, it becomes Released state, indicating that all the data can be restored manually.
Modify PV recycling policy methods
$ kubectl patch pv your-pv-name -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
View the recovery status of PV
[root@elasticsearch01 ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
ceph-rbd-pv 20Gi RWO Recycle Bound default/ceph-rbd-pv-claim 212d
jenkins-home-pv 40Gi RWO Recycle Bound default/jenkins-home-pvc 98d
pvc-e7967cfe-7ded-11e9-a09d-52540089b2b6 50Gi RWO Delete Bound default/zhidao-harbor-chartmuseum rbd 90d
pvc-e7974d1c-7ded-11e9-a09d-52540089b2b6 20Gi RWO Delete Bound default/zhidao-harbor-jobservice rbd 90d
pvc-e7985b55-7ded-11e9-a09d-52540089b2b6 2000Gi RWO Delete Bound default/zhidao-harbor-registry rbd 90d
pvc-e7d38097-7ded-11e9-a09d-52540089b2b6 20Gi RWO Delete Bound default/database-data-zhidao-harbor-database-0 rbd 90d
pvc-e7da3f3c-7ded-11e9-a09d-52540089b2b6 20Gi RWO Delete Bound default/data-zhidao-harbor-redis-0 rbd 90d
Recovering the modified state PV
[root@elasticsearch01 ~]# kubectl patch pv pvc-e7da3f3c-7ded-11e9-a09d-52540089b2b6 -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
persistentvolume/pvc-e7da3f3c-7ded-11e9-a09d-52540089b2b6 patched
View PV status has been changed to Retain the recovery
[root@elasticsearch01 ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
ceph-rbd-pv 20Gi RWO Recycle Bound default/ceph-rbd-pv-claim 212d
jenkins-home-pv 40Gi RWO Recycle Bound default/jenkins-home-pvc 98d
pvc-e7967cfe-7ded-11e9-a09d-52540089b2b6 50Gi RWO Delete Bound default/zhidao-harbor-chartmuseum rbd 90d
pvc-e7974d1c-7ded-11e9-a09d-52540089b2b6 20Gi RWO Delete Bound default/zhidao-harbor-jobservice rbd 90d
pvc-e7985b55-7ded-11e9-a09d-52540089b2b6 2000Gi RWO Delete Bound default/zhidao-harbor-registry rbd 90d
pvc-e7d38097-7ded-11e9-a09d-52540089b2b6 20Gi RWO Delete Bound default/database-data-zhidao-harbor-database-0 rbd 90d
pvc-e7da3f3c-7ded-11e9-a09d-52540089b2b6 20Gi RWO Retain Bound default/data-zhidao-harbor-redis-0 rbd 90d