All KB cards
Kubernetes – Remove a namespace stuck in terminating state

In case of a k8s namespace stuck in the terminating state, you can use the two below commands to ensure that there is no remaining ressources and to remove the finalizers of the ressource:

# declare the namespace that is stuck

Ensure there is no remaining ressource(s):

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $STUCKED_NS

And to remove the ressource finalizers:

kubectl get namespace $STUCKED_NS -o json \
  | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
  | kubectl replace --raw /api/v1/namespaces/$STUCKED_NS/finalize -f -

Thanks to teoincontatto @ for this tip