How to prevent the PV data of the delete policy from being cleared when the accidentally deleted PVC is in termination?
Problem Description
How to avoid the PV data from being cleared when the PVC is in the terminating state due to accidental deletion.
Alert Information
NA
Effective Troubleshooting Steps
- Directly deleting a PVC won't immediately delete it; instead, it waits for the POD using it to terminate. At this point, while the POD is still running, the PVC will be in a terminating state.
- Once the POD is cleaned up, the PVC will end its state. If the PV is configured with a delete strategy, the data will be cleared once the PVC is deleted.
- Therefore, two actions are necessary here: one is to change the PV's strategy so that it doesn't get deleted.
- The other is to have the PV rebind to a new PVC.
Root Cause
NA
Solution
- Use kubectl or the interface to directly edit the yaml file and change the PV's strategy to Retain.
- Save the PVC's yaml file, using
kubectl get pvc xxx > temp.yamlor copying the yaml file directly through the interface and saving it. - Forcefully clean and delete the PVC with
kubectl patch pvc xxxxx-pvc -n -p '{"metadata":{"finalizers":null}}'or use the SKE interface to edit the yaml and manually change the finalizers field to null. - Change the number of business replicas using the PVC to 0, allowing the PVC to automatically be deleted.
- At this point, the PV will be in an unusable state; edit the yaml file using kubectl or the interface UI to remove all the ClaimsRef fields in the PV, which will make the PV available again.
- Reapply the previously saved PVC configuration file
temp.yaml, allowing the PV to rebind to the PVC. - Then change the number of Workload replicas back to 1, which will restore the business operations, and the PV data will be preserved.
Scope of Operation Impact
NA
Is This a Temporary Solution?
NA
Recommendations and Summary
Those with the capability can look for solutions directly on open-source platforms. This process should be roughly the same.
Investigation Content
NA
https://support.sangfor.com.cn/cases/list?product_id=37&type=1&category_id=28643&isOpen=true