I want to delete all PersistentVolumeClaim in Kubernetes that have claim word in their name.
for example: claim-me-dot-com
How can I do it? thanks.
CodePudding user response:
You can use this to delete all PVCs whose names contain claim. You should check every namespace and then delete the PVC in that namespace. Otherwise, you may delete important PVCs.
export NAMESPACE=your-name-space
export DELETE_PHRASE=claim
kubectl get pvc -n NAMESPACE --no-headers=true | awk '{ print $2 }' | grep $DELETE_PHRASE | xargs kubectl delete pvc -n $NAMESPACE
To delete in bulk, you can use this for
script to delete all of the PVCs. Use this at your own RISK
for ns in `kubectl get ns --no-headers=true -o custom-columns=":metadata.name"`;
for pvc in `kubectl get pvc -n $ns --no-headers=true -o custom-columns=":metadata.name" | grep claim`;
kubectl delete pvc $pvc -n $ns;
done
done