When you create and delete resources and according objects in a namespace in your kubernetes cluster, you might just want to delete your namespace after your tests: kubectl delete ns test

stuck namespace

When namespace deletion seems stuck in a Terminating status, check if there are any object left over in your namespace:

If all is clean, but the namespace is stuck in Terminating, check (kubectl get ns test -o yaml) for Finalizers.

spec:
  finalizers:
  - kubernetes

Options from here:

delete the kubernetes namespace over API

(If you use the API direct, you loose all the checking usually done by kubectl!)

start the proxy to access the API

get the namespac json, overwrite the finalizers (just as we have done above with kubectl edit …) and store it in a temporary file

send the created test-ns.json to the KubeAPI

verify success

kubectl get ns test returns Error from server (NotFound): namespaces "test" not found

The namespace is now gone.

(un)expected side effects

Martin Heinz wrote with much greater detail, why messing with finalizers is a bad idea most of the time. So only use --force --grace-period=0 if you also take care of the resources which might stray around afterwards.