wesupport

Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Remove kubernetes namespace stuck in terminating | Guide

by | Feb 13, 2022

Remove Kubernetes namespace stuck in terminating with ease with Bobcares by your side.

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Let’s take a look at how our Support Team is ready to help customers remove Kubernetes namespace stuck in terminating status.

How to remove Kubernetes namespace stuck in terminating

If your Kubernetes namespace is stuck in the terminating status, you will notice something similar to this:

remove Kubernetes namespace stuck in terminating

 

If you are not sure which resources are still running in the stale namespace, the following command can come in handy:

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

Once you identify the resources, you can attempt deleting them with the –force flag. For example:

kubectl delete deployment/nginx -n  --grace-period=0 --force

After the deletion of the resources, the namespace control automatically terminates the namespace. However, if the resources are CRDs, and the deletion does not go ahead, it ends up in a hung state. In this scenario, the descriptor file looks similar to the one below:

{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "annotations": {
            "install.operator.istio.io/chart-owner": "Base",
            "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{\"install.operator.istio.io/chart-owner\":\"Base\"},\"labels\":{\"install.operator.istio.io/owner-group\":\"install.istio.io\",\"install.operator.istio.io/owner-kind\":\"IstioOperator\",\"install.operator.istio.io/owner-name\":\"profile-demo-customized\",\"istio-injection\":\"disabled\",\"istio-operator-managed\":\"Reconcile\"},\"name\":\"istio-system\"}}\n",
            "openpolicyagent.org/admission-control": "disabled"
        },
        "creationTimestamp": "2020-05-17T14:00:45Z",
        "labels": {
            "control-plane": "controller-manager",
            "install.operator.istio.io/owner-group": "install.istio.io",
            "install.operator.istio.io/owner-kind": "IstioOperator",
            "install.operator.istio.io/owner-name": "profile-demo-customized",
            "istio-injection": "disabled",
            "istio-operator-managed": "Reconcile",
            "network-name": "istio-system"
        },
        "name": "istio-system",
        "resourceVersion": "1333192",
        "selfLink": "/api/v1/namespaces/istio-system",
    },
}
    "spec": {
        "finalizers": [
            "kubernetes"
        ]
    },
    "status": {
        "phase": "Terminating"
    }
}

Another option according to our Support Techs, is removing the finalizer spec in order to allow Kubernetes to clear the namespace. In other words, we can remove the Kubernetes namespace in the terminating status with these steps:

  1. First, dump the namespace spec in json format as seen below:
    kubectl get ns  -o json > namespace.json
  2. Next, we edit the namespace.json and then remove the finalizer portion in the spec. So, we have to change to from:
    ”spec”: {
    	“finalizers”:
      },

    to:

    ”spec”: {
      },

    Alternatively, we can remove everything inside the spec to get the job done.

  3. After that, we have to manually patch the namespace with the command below:
    kubectl replace --raw "/api/v1/namespaces//finalize" -f namespace.json

[Looking for a solution to another query? We are just a click away.]

Conclusion

To conclude, our skilled Support Engineers at Bobcares demonstrated how to remove the Kubernetes namespace in terminating status.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags