更改 PersistentVolume 的回收策略
2019-08-22 本文已影响0人
三杯水Plus
参考文档
https://kubernetes.io/zh/docs/tasks/administer-cluster/change-pv-reclaim-policy/
PV的回收策略
PersistentVolumes 可以有多种回收策略,包括 “Retain”、”Recycle” 和 “Delete”。对于动态配置的 PersistentVolumes 来说,默认回收策略为 “Delete”。这表示当用户删除对应的 PersistentVolumeClaim 时,动态配置的 volume 将被自动删除。如果 volume 包含重要数据时,这种自动行为可能是不合适的。那种情况下,更适合使用 “Retain” 策略。使用 “Retain” 时,如果用户删除 PersistentVolumeClaim,对应的 PersistentVolume 不会被删除。相反,它将变为 Released 状态,表示所有的数据可以被手动恢复。
修改PV回收策略方法
kubectl patch pv your-pv-name -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
查看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
修改PV的回收状态
[root@elasticsearch01 ~]# kubectl patch pv pvc-e7da3f3c-7ded-11e9-a09d-52540089b2b6 -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
persistentvolume/pvc-e7da3f3c-7ded-11e9-a09d-52540089b2b6 patched
查看PV回收状态已经改成Retain了
[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