[问题已处理]-kubernetes误删除pv失败后进行恢复

导语:误删除pv后如何恢复

如图:名为dwuserspv的pv已经删除 但是因为对应的pvc没有删除。状态一直为Terminating状态

[问题已处理]-kubernetes误删除pv失败后进行恢复_第1张图片

先保存一下对应的pvc信息

kubectl get pv/dwuserspv   -o yaml > /tmp/dwuserspv.yaml
kubectl get pvc/dwuserspvc   -o yaml > /tmp/dwuserspvc.yaml

此时pv的yaml文件 /tmp/dwuserspv.yaml大致如下

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/bound-by-controller: "yes"
  creationTimestamp: "2020-05-11T11:11:19Z"
  deletionGracePeriodSeconds: 0
  deletionTimestamp: ""
  finalizers:
  - kubernetes.io/pv-protection
  name: dwuserspv
  resourceVersion: "197244835"
  selfLink: /api/v1/persistentvolumes/dwuserspv
  uid: 2414ff04-9378-11ea-9574-ac1f6b9ec91e
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 1Ei
  cephfs:
    monitors:
    - pai-rtx-01
    - pai-rtx-02
    - pai-rtx-03
    - pai-2080ti-01
    - pai-2080ti-02
    path: /users
    secretFile: /etc/ceph/admin.secret
    user: admin
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: dwuserspvc
    namespace: default
    resourceVersion: "15567180"
    uid: 24183657-9378-11ea-9574-ac1f6b9ec91e
  mountOptions:
  - client_mds_namespace=1
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem
status:
  phase: Bound

这里尝试过把yaml中的delete信息删除再强制应用,不过并未生效

deletionGracePeriodSeconds: 0
deletionTimestamp: “”

kubectl  edit pv dwuserspv
# 删除下面2行 修改完成之后pv会被删除 pvc会变成lost状态
#   finalizers:
#  - kubernetes.io/pv-protection

[问题已处理]-kubernetes误删除pv失败后进行恢复_第2张图片

重新通过命令kubectl apply创建pv

即将备份文件中的delete信息删除

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/bound-by-controller: "yes"
  creationTimestamp: "2020-05-11T11:11:19Z"
  finalizers:
  - kubernetes.io/pv-protection
  name: dwuserspv
  resourceVersion: "197218875"
  selfLink: /api/v1/persistentvolumes/dwuserspv
  uid: 2414ff04-9378-11ea-9574-ac1f6b9ec91e
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 1Ei
  cephfs:
    monitors:
    - pai-rtx-01
    - pai-rtx-02
    - pai-rtx-03
    - pai-2080ti-01
    - pai-2080ti-02
    path: /users
    secretFile: /etc/ceph/admin.secret
    user: admin
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: dwuserspvc
    namespace: default
    resourceVersion: "15567180"
    uid: 24183657-9378-11ea-9574-ac1f6b9ec91e
  mountOptions:
  - client_mds_namespace=1
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem
status:
  phase: Bound

再次查看pv恢复了,pvc也不是lost状态了

[问题已处理]-kubernetes误删除pv失败后进行恢复_第3张图片

参考

https://wjrsbu.smartapps.cn/zhihu/article?id=68601257&isShared=1&_swebfr=1&_swebFromHost=baiduboxapp

https://www.hangge.com/blog/cache/detail_3092.html

https://www.cnblogs.com/wangzy-Zj/p/14115491.html

你可能感兴趣的:(kubernetes,问题已处理,kubernetes,运维)