Deleting namespaces in zombie state (Terminating status) OCP4.x

Project cannot be deleted because of the finalizer kubernetes not being removed from the project definition.

(working with Openshift 4.x)

1- Create a file from all namespaces in terminating status

$ oc get projects |grep Terminating |awk '{print $1}' > terminating-ns

2- Create a shell script to iterate through all namespaces to create a json file

while read p; do
echo $p
oc get project $p -o json |grep -v "kubernetes" > $p.json

done <$filename

3- Run the script

$ chmod +x
$ ./

4- Replace each JSON file with correct metadata values according to Openshift 4.2

Where (this can be improved with jq at script):

"kind": "Project" –> "kind": "Namespace"
apiVersion: "" –> apiVersion: "v1"

5- Create a proxy for OCP API

oc proxy --port=8080 &

6- Create a shell script to update namespace definition with the json file, so the namespace can finally be purged from cluster

while read p; do
curl -k -H "Content-Type: application/json" -X PUT --data-binary @$p.json localhost:8080/api/v1/namespaces/$p/finalize;
done <$filename

7- Run the script

$ chmod +x
$ ./

8- Check if the namespace was killed

$ oc get projects |grep Terminating

Credits (kubernetes based):


Leave A Comment