Skip to content

Instantly share code, notes, and snippets.

@d3athkai
Created May 25, 2024 13:14
Show Gist options
  • Save d3athkai/8d81b83f4c5598d5325acf614fec1d58 to your computer and use it in GitHub Desktop.
Save d3athkai/8d81b83f4c5598d5325acf614fec1d58 to your computer and use it in GitHub Desktop.

Kubernetes Tips and Tricks

A collection of some of my useful Kubernetes Tips and Tricks.


Unable to delete Custom Resource Definition (CRD)

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> 

Unable to delete Namespace (NS)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment