A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


Kubernetes Stuck Deleting Namespace - ingress-nginx

Kubernetes error when deleting network. 

 

Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": serviceaccounts "ingress-nginx" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": configmaps "ingress-nginx-controller" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": clusterroles.rbac.authorization.k8s.io "ingress-nginx" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": clusterrolebindings.rbac.authorization.k8s.io "ingress-nginx" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": roles.rbac.authorization.k8s.io "ingress-nginx" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": rolebindings.rbac.authorization.k8s.io "ingress-nginx" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": services "ingress-nginx-controller-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": services "ingress-nginx-controller" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": deployments.apps "ingress-nginx-controller" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": ingressclasses.networking.k8s.io "nginx" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": validatingwebhookconfigurations.admissionregistration.k8s.io "ingress-nginx-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": serviceaccounts "ingress-nginx-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": clusterroles.rbac.authorization.k8s.io "ingress-nginx-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": clusterrolebindings.rbac.authorization.k8s.io "ingress-nginx-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": roles.rbac.authorization.k8s.io "ingress-nginx-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": rolebindings.rbac.authorization.k8s.io "ingress-nginx-admission" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": jobs.batch "ingress-nginx-admission-create" not found
Error from server (NotFound): error when deleting "k8s-configuration/ingress-nginx.yml": jobs.batch "ingress-nginx-admission-patch" not found

 

The error message:

Error from server (Forbidden): error when creating "k8s-configuration/ingress-nginx.yml": serviceaccounts "ingress-nginx" is forbidden: unable to create new content in namespace ingress-nginx because it is being terminated

means that the namespace ingress-nginx is in the process of being deleted, so Kubernetes is not allowing any new resources (like a service account) to be created inside it.


How to Fix This - Check the namespace status

kubectl get namespaces

If you see ingress-nginx with a Terminating status, then it’s stuck during deletion.


Force Delete the Stuck Namespace

  1. Edit the namespace and remove finalizers:

kubectl get namespace ingress-nginx -o json > tmp-ingress-nginx.json
  1. Open the file and remove the "finalizers" section. It looks like:

"spec": {
  "finalizers": [
    "kubernetes"
  ]
}

Just remove that array entirely (or set it to an empty list []).

  1. Apply the edited JSON back:

kubectl replace --raw "/api/v1/namespaces/ingress-nginx/finalize" -f ./tmp-ingress-nginx.json

🔁 Recreate the Namespace

Once deleted:

kubectl create namespace ingress-nginx

Then re-run your ingress-nginx.yml creation command.

 

Add comment