I am writing a shell script to create and tear down a persistent volume and a persistent volume claim. While tearing down, I have to get into the persistent volume claim resource and delete the finalizer limitation, using
kubectl get pvc example-pvc -o yaml > hype.yaml && \
sed -i '/^[^#]*finalizer/c\' hype.yaml && \
sed -i '/^[^#]*pvc-protection/c\' hype.yaml && \
kubectl replace pvc example-pvc -o yaml -f hype.yaml.
The hype.yaml
file does not carry the limitation anymore,
persistentvolumeclaim/example-pvc replaced
is displayed, but the resource itself, as indicated through kubectl edit pvc example-pvc
, is unchanged and thus refuses to tear down the persistent volume claim.
Any idea why this is and how to fix it?
On @Kamol Hasan's request:
$kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
example-pvc Terminating example-pv 10Gi RWX
The second requested command yields a very long .yaml file, but, as I said, where the finalizer lines are absent.
If your PVC is attached to a PV, then it won't terminate unless your PV is also terminated. It will be stuck in that terminating state forever. Update the PV, then update the PVC. You could simply put the PV and PVC in the same yaml and run kubectl apply -f
.