PersistentVolume的回收策略
PersistentVolume可以有各种回收策略,包括Retain、Recycle和Delete。对于动态供应的持久卷,默认的回收策略是Delete。这意味着当用户删除相应的PersistentVolumeClaim时,动态供应的卷将自动删除。
如果卷中包含宝贵的数据,这种自动行为可能不合适。在这种情况下,使用Retain策略更合适。使用Retain策略,如果用户删除PersistentVolumeClaim,则不会删除相应的PersistentVolume。
相反,它被移动到 Released阶段,在那里它的所有数据都可以手动恢复。
[root@k8s-master1 opt]# kubectl get pv --all-namespaces NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-1a6ba283-b16a-4cb4-b4a7-b4506534a9a9 20Gi RWO Delete Bound kube-system/prometheus-data-prometheus-0 managed-nfs-storage 26d pvc-33a6230c-481f-4d61-aff6-89d95bef74d9 4Gi RWO Delete Bound kube-system/alertmanager managed-nfs-storage 26d pvc-685576e3-cca1-4f6d-86b1-2e4395c6d499 5Gi RWO Delete Bound kube-system/grafana-data-grafana-0 managed-nfs-storage 26d
[root@k8s-master1 opt]# kubectl patch pv pvc-685576e3-cca1-4f6d-86b1-2e4395c6d499 -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}' persistentvolume/pvc-685576e3-cca1-4f6d-86b1-2e4395c6d499 patched [root@k8s-master1 opt]# kubectl get pv --all-namespaces NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-1a6ba283-b16a-4cb4-b4a7-b4506534a9a9 20Gi RWO Delete Bound kube-system/prometheus-data-prometheus-0 managed-nfs-storage 26d pvc-33a6230c-481f-4d61-aff6-89d95bef74d9 4Gi RWO Delete Bound kube-system/alertmanager managed-nfs-storage 26d pvc-685576e3-cca1-4f6d-86b1-2e4395c6d499 5Gi RWO Retain Bound kube-system/grafana-data-grafana-0 managed-nfs-storage 26d