Description#
After installing a helm deployment or testing something and you removed everything, sometimes we faced a stuck namespace, so how to kill it?
Terminating stuck namespace#
- Set the namespace name, then run the command below:
NAMESPACE=stuck-namespace
kubectl get namespace "$NAMESPACE" -o json \
| tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
| kubectl replace --raw "/api/v1/namespaces/$NAMESPACE/finalize" -f -
- Or, if you have
jqinstalled:
kubectl get namespace "$NAMESPACE" -o json \
| jq '.spec.finalizers = []' \
| kubectl replace --raw "/api/v1/namespaces/$NAMESPACE/finalize" -f -
Tip: A namespace usually gets stuck because an API service or a custom resource inside it can no longer be cleaned up.
kubectl get namespace "$NAMESPACE" -o yamlshows the reason understatus.conditions.