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.
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.
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
The solution below is restricted to the current namespace:
kubectl get pvc -o name | grep "claim-me-dot-com" | xargs -n 1 kubectl delete
To delete pvc from all namespaces:
kubectl get pvc -o name -A | grep "claim-me-dot-com" | xargs -n 1 kubectl delete
Another way would be to delete multiple objects based on their labels.
e.g.
kubectl delete pvc -l 'app.kubernetes.io/component in (<FIRST_VALUE>, <SECOND_VALUE>)'