A collection of some of my useful Kubernetes Tips and Tricks.
If the normal way of deleting a CRD does not work, ie:
kubectl delete crd/<CRD_NAME>
Try the following instead:
kubectl patch crd/<CRD_NAME> -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl delete crd/<CRD_NAME>
If the normal way of deleting a NS does not work, ie:
kubectl delete ns <namespace>
Try the following instead:
for ns in $(kubectl get ns --field-selector status.phase=Terminating -o jsonpath='{.items[*].metadata.name}')
do
kubectl get ns $ns -ojson | jq '.spec.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/$ns/finalize" -f -
done
for ns in $(kubectl get ns --field-selector status.phase=Terminating -o jsonpath='{.items[*].metadata.name}')
do
kubectl get ns $ns -ojson | jq '.metadata.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/$ns/finalize" -f -
done