介绍

最近一直在玩 EKS(Elastic Kubernetes Service -- Amazon EKS) 和 KubeSphere。 因为之前没有使用过 EKS 和 KubeSphere,所以这个过程也是一个试错的过程,在我使用 KubeSphere 的时候发现有一个日志服务,在好奇心的驱使下,我创建了它。

在我创建了日志服务(KubeSphere Logging System)以后,我发现我并不想使用它。(可能我只是想看看它到底是什么吧。)强迫症的我就想把它给删除掉。于是我在我的 EKS 中对他进行了强制删除:

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

让人尴尬的是,这个 Namespace 并没有立马删除,我自我安慰道,可能 Namespace 下边有其他没有删除的资源在等待删除,我再等等。。。

过了半个小时,再次查看删除进度:

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

它好像这地卡在了 Terminating 的状态。我试着寻找解决方法,参考这个 isue:http://github.com/kubernetes/kubernetes/issues/60807。但是这种方法要通过 API 才可以实现。EKS 是托管在 AWS 中的,我根本没有办法去操作 EKS 的后台。

终于我在这个 issue 中找到了答案:https://github.com/kubernetes/kubernetes/issues/60807#issuecomment-663853215

如何彻底删除 namespace

获取 namespace 的详情信息并转为 json

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

打开 json 文件编辑

{
"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"
}
}

找到 spec 将 finalizers 下的 kubernetes 删除。

具体如下

{
"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"
}
}

执行清理命令

现在我们只需要一条命令 就可以彻底删除这个 Namespace。

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

执行完以后,你需要等待一会,再次执行命令检查 Namespace。

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

最后的检查

$ 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

再次查看的时候,它已经不存在了。

本文由博客一文多发平台 OpenWrite 发布!

删除 KubeSphere 中一直卡在 Terminating 的 Namespace的更多相关文章

  1. 聊聊 Kubernetes Pod or Namespace 卡在 Terminating 状态的场景

    这个话题,想必玩过kubernetes的同学当不陌生,我会分Pod和Namespace分别来谈. 开门见山,为什么Pod会卡在Terminationg状态? 一句话,本质是API Server虽然标记 ...

  2. 容器化 | 在 KubeSphere 中部署 MySQL 集群

    程润科 数据库研发工程师,目前从事 RadonDB MySQL Kubernetes 研发,热衷于研究数据库内核.K8s 相关技术. 张莉梅 高级文档工程师,目前负责数据库产品文档开发.维护和管理工作 ...

  3. JSON相关知识,转载:删除JSON中数组删除操作

    一:JSON是什么 JSONg格式:对象是一个无序的“名称/值”对的集合. 对象以括号开始,括号结束. 名称冒号分隔值. "名称/值"之间用逗号分隔 例: var people = ...

  4. C# 删除字符串中的中文

    /// <summary> /// 删除字符串中的中文 /// </summary> public static string Delete中文(string str) { s ...

  5. 如何删除datatable中的一行数据

    在C#中,如果要删除DataTable中的某一行,大约有以下几种办法: 1,使用DataTable.Rows.Remove(DataRow),或者DataTable.Rows.RemoveAt(ind ...

  6. iOS开发-删除字典中的null

    删除字典中的null 我们在处理数据库接口的过程中,如果数据中出现null,我们是没法处理的.我在使用NSUserDaults保存后,出现崩溃. null产生原因 null是后台在处理数据的时候,如果 ...

  7. [java]删除数组中的某一个元素

    package org.company.project.test; import java.util.Arrays; import java.util.Scanner; public class Ar ...

  8. SqlServer删除表中重复记录

    重复记录:有两个意义上的重复记录 一是完全重复的记录,也即所有字段均重复的记录: 二是部分关键字段重复的记录,比如Name字段重复,而其他字段不一定重复或都重复可以忽略. 1.对于第一种重复,比较容易 ...

  9. 查询和删除表中重复数据sql语句

      1.查询表中重复数据.select * from peoplewhere peopleId in (select   peopleId   from   people   group   by   ...

  10. Java删除数据库中的数据

    1:删除数据库中数据表中的数据同样也是一个非常用的技术,使用executeUpdate()方法执行用来做删除SQL的语句可以删除数据库表中的数据 2:本案例使用Statement接口中的execute ...

随机推荐

  1. 读论文《IMPALA: Scalable Distributed Deep-RL with Importance Weighted Actor-Learner Architectures》

    论文地址: https://arxiv.org/pdf/1802.01561v2.pdf 论文<IMPALA: Scalable Distributed Deep-RL with Importa ...

  2. 位移运算符 1<<4

    转载自 https://www.cnblogs.com/ljangle/p/13036992.html 位运算 1 << 4   static final int DEFAULT_INIT ...

  3. 【CMake系列】06-项目结构与输出路径管理

    为了对大型项目实现更好的管理[模块化协作开发等等],cmake 提供了很多指令,可以对项目的结构进行调整.管理,便于项目的合理规划.本文我们要学习的就是 项目结构的设置,以及 构建程序等 输出路径的设 ...

  4. C#读写图片文件到Access数据库中

    今天学习了把图片文件读写到数据库中,我是用的Access数据库,SQL还没去测试,不过都差不多 数据库表的样式 练习嘛就随便弄了下,说明下图片转成的字符串要用备注类型才可以哦 如果用的Sql数据库的话 ...

  5. Win32 GDI 在内存中绘制彩色的位图

    Wind32 GDI在内存中绘制彩色位图 1创建兼容的内存DC hPicture为创建的静态文本框控件句柄 LRESULT OnPaint(HWND hWnd) { PAINTSTRUCT ps; H ...

  6. C# WebSocket Fleck 源码解读

    最近在维护公司旧项目,偶然发现使用Fleck实现的WebSocket主动推送功能,(由于前端页面关闭时WebSocket Server中执行了多次OnClone事件回调并且打印了大量的关闭日志,),后 ...

  7. k8s手动安装

    一.主节点安装 设置主机名hostnamectl set-hostname masterhostnamectl set-hostname node01 修改hosts文件vim /etc/hosts1 ...

  8. 全网最适合入门的面向对象编程教程:38 Python常用复合数据类型-使用列表实现堆栈、队列和双端队列

    全网最适合入门的面向对象编程教程:38 Python 常用复合数据类型-使用列表实现堆栈.队列和双端队列 摘要: 在 Python 中,列表(list)是一种非常灵活的数据结构,可以用来实现堆栈(st ...

  9. XeLaTeX 无法编译含有经过 pdfcrop 裁剪的 PDF 文件的文档

    今天在写 LaTeX 文档时踩了个大坑,我在文档里插入了一个 PDF 图片之后文档无法编译了. 于是我去掉多余代码,做了一个最小工作示例: \documentclass{article} \usepa ...

  10. ASP.NET Core – Filter

    介绍 Filter 类似 Middleware,只是它集中在处理 request 的前后, 站 MVC 角度看就是 before 和 after action, 站 Razor Pages 角度就是 ...