introduce

Lately I’ve been playing EKS (Elastic Kubernetes Service — Amazon EKS) and KubeSphere. Since I had never used EKS or KubeSphere before, this process was also a trial and error process. When I was using KubeSphere, I found a logging service and created it out of curiosity.

After I created the KubeSphere Logging System, I found that I didn’t want to use it. (Maybe I just wanted to see what it was.) I’m obsessive-compulsive and I just want to delete it. So I forcibly deleted him in my EKS:

$ kubectl delete ns kubesphere-logging-system  --force --grace-period=0
Copy the code

Embarrassingly, the Namespace was not deleted immediately. I consoled myself by saying, maybe there are other undeleted resources waiting to be deleted under the Namespace, I will wait…

After half an hour, check the deletion progress again:

$ kubectl get  ns  kubesphere-logging-system
NAME                              STATUS        AGE
kubesphere-logging-system         Terminating   6d19h
Copy the code

It’s like the ground is stuck in Terminating condition. I’m trying to find a solution, check out isue: github.com/kubernetes/… API can be implemented. EKS is hosted in AWS, and I have no way to operate the background of EKS.

Finally I found the answer in this issue: github.com/kubernetes/…

How do I completely delete a namespace

Gets the namespace details and converts them to JSON

$ kubectl get namespace kubesphere-logging-system -o json > kubesphere-logging-system.json
Copy the code

Open the JSON file for editing

{
    "apiVersion": "v1"."kind": "Namespace"."metadata": {
        "creationTimestamp": "2021-12-31T05:03:58Z"."deletionTimestamp": "2022-01-05T08:05:40Z"."labels": {
            "kubesphere.io/namespace": "kubesphere-logging-system"."kubesphere.io/workspace": "system-workspace"
        },
        "managedFields": [{"apiVersion": "v1"."fieldsType": "FieldsV1"."fieldsV1": {
                    "f:metadata": {
                        "f:labels": {
                            ".": {},
                            "f:kubesphere.io/namespace": {}},"f:ownerReferences": {
                            ".": {},
                            "k:{\"uid\":\"6d535470-2592-4f3c-a155-eabc362c339d\"}": {
                                ".": {},
                                "f:apiVersion": {},
                                "f:blockOwnerDeletion": {},
                                "f:controller": {},
                                "f:kind": {},
                                "f:name": {},
                                "f:uid": {}}}}},"manager": "controller-manager"."operation": "Update"."time": "2021-12-31T05:04:01Z"
            },
            {
                "apiVersion": "v1"."fieldsType": "FieldsV1"."fieldsV1": {
                    "f:metadata": {
                        "f:labels": {
                            "f:kubesphere.io/workspace": {}}}."f:status": {
                        "f:phase": {}}}."manager": "kubectl"."operation": "Update"."time": "2021-12-31T05:04:01Z"
            },
            {
                "apiVersion": "v1"."fieldsType": "FieldsV1"."fieldsV1": {
                    "f:status": {
                        "f:conditions": {
                            ".": {},
                            "k:{\"type\":\"NamespaceContentRemaining\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceDeletionContentFailure\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceDeletionDiscoveryFailure\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceDeletionGroupVersionParsingFailure\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceFinalizersRemaining\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}}}}},"manager": "kube-controller-manager"."operation": "Update"."time": "2022-01-05T08:05:47Z"}]."name": "kubesphere-logging-system"."ownerReferences": [{"apiVersion": "tenant.kubesphere.io/v1alpha1"."blockOwnerDeletion": true."controller": true."kind": "Workspace"."name": "system-workspace"."uid": "6d535470-2592-4f3c-a155-eabc362c339d"}]."resourceVersion": "7376520"."uid": "2b76e9b1-75f2-4a2e-a819-73b36aea188e"
    },
    "spec": {
        "finalizers": [
            "kubernetes"},"status": {
        "conditions": [{"lastTransitionTime": "2022-01-05T08:05:47Z"."message": "All resources successfully discovered"."reason": "ResourcesDiscovered"."status": "False"."type": "NamespaceDeletionDiscoveryFailure"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "All legacy kube types successfully parsed"."reason": "ParsedGroupVersions"."status": "False"."type": "NamespaceDeletionGroupVersionParsingFailure"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "All content successfully deleted, may be waiting on finalization"."reason": "ContentDeleted"."status": "False"."type": "NamespaceDeletionContentFailure"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "Some resources are remaining: fluentbits.logging.kubesphere.io has 1 resource instances"."reason": "SomeResourcesRemain"."status": "True"."type": "NamespaceContentRemaining"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "Some content in the namespace has finalizers remaining: fluentbit.logging.kubesphere.io in 1 resource instances"."reason": "SomeFinalizersRemain"."status": "True"."type": "NamespaceFinalizersRemaining"}]."phase": "Terminating"}}Copy the code

Find specs and delete Kubernetes in finalizers.

Specific as follows

{
    "apiVersion": "v1"."kind": "Namespace"."metadata": {
        "creationTimestamp": "2021-12-31T05:03:58Z"."deletionTimestamp": "2022-01-05T08:05:40Z"."labels": {
            "kubesphere.io/namespace": "kubesphere-logging-system"."kubesphere.io/workspace": "system-workspace"
        },
        "managedFields": [{"apiVersion": "v1"."fieldsType": "FieldsV1"."fieldsV1": {
                    "f:metadata": {
                        "f:labels": {
                            ".": {},
                            "f:kubesphere.io/namespace": {}},"f:ownerReferences": {
                            ".": {},
                            "k:{\"uid\":\"6d535470-2592-4f3c-a155-eabc362c339d\"}": {
                                ".": {},
                                "f:apiVersion": {},
                                "f:blockOwnerDeletion": {},
                                "f:controller": {},
                                "f:kind": {},
                                "f:name": {},
                                "f:uid": {}}}}},"manager": "controller-manager"."operation": "Update"."time": "2021-12-31T05:04:01Z"
            },
            {
                "apiVersion": "v1"."fieldsType": "FieldsV1"."fieldsV1": {
                    "f:metadata": {
                        "f:labels": {
                            "f:kubesphere.io/workspace": {}}}."f:status": {
                        "f:phase": {}}}."manager": "kubectl"."operation": "Update"."time": "2021-12-31T05:04:01Z"
            },
            {
                "apiVersion": "v1"."fieldsType": "FieldsV1"."fieldsV1": {
                    "f:status": {
                        "f:conditions": {
                            ".": {},
                            "k:{\"type\":\"NamespaceContentRemaining\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceDeletionContentFailure\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceDeletionDiscoveryFailure\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceDeletionGroupVersionParsingFailure\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}},"k:{\"type\":\"NamespaceFinalizersRemaining\"}": {
                                ".": {},
                                "f:lastTransitionTime": {},
                                "f:message": {},
                                "f:reason": {},
                                "f:status": {},
                                "f:type": {}}}}},"manager": "kube-controller-manager"."operation": "Update"."time": "2022-01-05T08:05:47Z"}]."name": "kubesphere-logging-system"."ownerReferences": [{"apiVersion": "tenant.kubesphere.io/v1alpha1"."blockOwnerDeletion": true."controller": true."kind": "Workspace"."name": "system-workspace"."uid": "6d535470-2592-4f3c-a155-eabc362c339d"}]."resourceVersion": "7376520"."uid": "2b76e9b1-75f2-4a2e-a819-73b36aea188e"
    },
    "spec": {
        "finalizers": []},"status": {
        "conditions": [{"lastTransitionTime": "2022-01-05T08:05:47Z"."message": "All resources successfully discovered"."reason": "ResourcesDiscovered"."status": "False"."type": "NamespaceDeletionDiscoveryFailure"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "All legacy kube types successfully parsed"."reason": "ParsedGroupVersions"."status": "False"."type": "NamespaceDeletionGroupVersionParsingFailure"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "All content successfully deleted, may be waiting on finalization"."reason": "ContentDeleted"."status": "False"."type": "NamespaceDeletionContentFailure"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "Some resources are remaining: fluentbits.logging.kubesphere.io has 1 resource instances"."reason": "SomeResourcesRemain"."status": "True"."type": "NamespaceContentRemaining"
            },
            {
                "lastTransitionTime": "2022-01-05T08:05:47Z"."message": "Some content in the namespace has finalizers remaining: fluentbit.logging.kubesphere.io in 1 resource instances"."reason": "SomeFinalizersRemain"."status": "True"."type": "NamespaceFinalizersRemaining"}]."phase": "Terminating"}}Copy the code

Execute cleanup command

Now we only need one command to remove the Namespace completely.

 $ kubectl replace --raw "/api/v1/namespaces/kubesphere-logging-system/finalize" -f ./kubesphere-logging-system.json 
Copy the code

After executing, you need to wait for a while and run the command again to check the Namespace.

 $ kubectl replace --raw "/api/v1/namespaces/kubesphere-logging-system/finalize" -f ./kubesphere-logging-system.json 
Copy the code

Final check

$ kubectl get ns kubesphere-logging-system
Error from server (NotFound): namespaces "kubesphere-logging-system" not found

$ kubectl get ns 
NAME                              STATUS   AGE
default                           Active   23d
kubesphere-controls-system        Active   9d
kubesphere-devops-system          Active   9d
kubesphere-devops-worker          Active   16h
kubesphere-monitoring-federated   Active   9d
kubesphere-monitoring-system      Active   9d
kubesphere-sample-dev             Active   8d
kubesphere-system                 Active   9d
Copy the code

When I checked again, it was gone.

This article is published by OpenWrite!