How to force delete the Kubernetes namespace

The
You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off
The

The
The

Namespaces are a way to divide Kubernetes cluster resources among multiple users and teams. They are designed to be used in environments with multiple users distributed across multiple teams or projects. For Kubernetes clusters with only a few users, there may be no need to create or consider namespaces.

You may have created a Kubernetes cluster using the following command Kubem As described in our Kubernetes installation guide. When deploying, you have deleted the namespace, then deleted all the namespaces, and want to reuse the same name to recreate the resource. However, your namespace stays at Termination status.

[[email protected] ~]$ kubectl delete ns developer
namespace "developer" deleted

[[email protected] ~]$ kubectl get ns developer
NAME STATUS AGE
developer Terminating 1h

We can solve this problem in many ways. In this article, I will guide you to use the following methods to solve this problem kubectl proxy.

Step 1: Edit the namespace

First, we need to edit the termination namespace in order to delete Kubernetes Terminator inside specification. The finalizer is a value set in the kubernetes resource. When there are finalizers, it can be ensured that the resource cannot be hard deleted when they exist. This explains why the namespace will remain terminated if it is not properly deleted.

We can do this using JSON format. Run the following command:

[[email protected] ~]$ kubectl get ns developer -o json  > tmp.json
[[email protected] ~]$ vim  tmp.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "developer",
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"conditions": [
{
"lastTransitionTime": "2020-07-19T12:29:58Z",
"message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request",
"reason": "DiscoveryFailed",
"status": "True",
"type": "NamespaceDeletionDiscoveryFailure"
},
{
"lastTransitionTime": "2020-07-19T12:30:02Z",
"message": "Failed to delete all resource types, 1 remaining: unexpected items still remain in namespace: developer for gvr: /v1, Resource=pods",
"reason": "ContentDeletionFailed",
"status": "True",
"type": "NamespaceDeletionContentFailure"
}
],
"phase": "Terminating"
}
}

and so Normalizer The value should look like this:

[[email protected] ~]$ cat tmp.json
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "developer"
},
"spec": {
"finalizers": []
}
}

Step 2: Open a new terminal

Second, we will use an HTTP proxy to access the Kubernetes API. The proxy server allows us to explore the kubernetes API using the following curl, wget, Or browser. We can do this by running the following command on the new terminal:

[[email protected] ~]$ kubectl proxy
Starting to serve on 127.0.0.1:800

Step 3: Apply the edited JSON file

Finally, we will use curl The namespace is applied without problematic finalizers.

[[email protected] ~]$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/developer/finalize
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "developer",
"spec": {},
"status": {
"phase": "Terminating",
"conditions": [
{
"type": "NamespaceDeletionDiscoveryFailure",
"status": "True",
"lastTransitionTime": "2020-07-19T12:53:50Z",
"reason": "DiscoveryFailed",
"message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request"
},
{
"type": "NamespaceDeletionGroupVersionParsingFailure",
"status": "False",
"lastTransitionTime": "2020-07-19T12:53:54Z",
"reason": "ParsedGroupVersions",
"message": "All legacy kube types successfully parsed"
},
{
"type": "NamespaceDeletionContentFailure",
"status": "False",
"lastTransitionTime": "2020-07-19T12:53:54Z",
"reason": "ContentDeleted",
"message": "All content successfully deleted"
}
]
}

We have successfully deleted the namespace.

[[email protected] ~]$ kubectl get ns developer
Error from server (NotFound): namespaces "developer" not found

Check the following courses that can help you master Kubernetes Internals.


Certified Kubernetes Administrator (CKA) and practice test

★★★★★
(12755)

$14.88

$ 154.54

In stock

Buy now

How to force delete the Kubernetes namespaceUdemy.com


Kubernetes certified application developer with testing (CKAD)

Kubernetes certified application developer with testing (CKAD)

★★★★★
(6014)

$14.88

$148.81

In stock

Buy now

How to force delete the Kubernetes namespaceUdemy.com


Learn DevOps: The complete Kubernetes course

Learn DevOps: The complete Kubernetes course

★★★★☆
(10907)

$19.46

$45.78

In stock

Buy now

How to force delete the Kubernetes namespaceUdemy.com

More articles about Kubernetes:

Use kubeadm to install a Kubernetes cluster on Ubuntu

Use Kompose to migrate Docker Compose applications to Kubernetes

Install the Kubernetes dashboard using NodePort

The
You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off
The

The
The

Sidebar