当前位置: 首页 > news >正文

Kubernetes中无法删除一个对象,持续处于Terminating状态的解决方案

文章目录

  • 1. 问题描述
  • 2. 解决方案

1. 问题描述

未使用uninstall.yml文件删除longhorn组件的时候,从而造成无法删除longhorn-system名称空间的解决方案

此时使用kubectl delete ns longhorn-system已经无法完成删除操作了。会持续显示terminating的状态

2. 解决方案

此时可以将无法删除且一直处于terminating状态的对象以json格式导出为文件,此处的对象是名为longhorn-system的名称空间。该名称空间导出为json格式,然后然后去掉其中的spec以及status字段信息。

具体如下:

[root@c7u6s5:longhorn]# kubectl get ns longhorn-system -o json > longhron-system.json
[root@c7u6s5:longhorn]# vim longhorn-system.json
[root@c7u6s5:longhorn]# cat longhorn-system.json 
{"apiVersion": "v1","kind": "Namespace","metadata": {"annotations": {"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"longhorn-system\"}}\n"},"creationTimestamp": "2022-03-13T08:48:06Z","deletionTimestamp": "2022-03-21T09:09:02Z","labels": {"kubernetes.io/metadata.name": "longhorn-system"},"name": "longhorn-system","resourceVersion": "13365518","uid": "9182f43a-e302-4fe5-b8b4-b37bde46228a"}
}
[root@c7u6s5:longhorn]# 

上述就是将spec以及status字段去掉之后的内容。

然后启动kubectl proxy代理,通过curl命令直接与api服务器通信,通过@longhorn-system.json语法指定传输上述生成的文件,表示对该文件中的对象执行finalize操作。具体如下:

[root@c7u6s5:longhorn]# curl -k -H 'Content-Type: application/json' -XPUT --data-binary @longhorn-system.json http://127.0.0.1:8001/api/v1/namespaces/longhorn-system/finalize
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {"name": "longhorn-system","uid": "9182f43a-e302-4fe5-b8b4-b37bde46228a","resourceVersion": "13365518","creationTimestamp": "2022-03-13T08:48:06Z","deletionTimestamp": "2022-03-21T09:09:02Z","labels": {"kubernetes.io/metadata.name": "longhorn-system"},"annotations": {"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"longhorn-system\"}}\n"},"managedFields": [{"manager": "kubectl-client-side-apply","operation": "Update","apiVersion": "v1","time": "2022-03-13T08:48:06Z","fieldsType": "FieldsV1","fieldsV1": {"f:metadata":{"f:annotations":{".":{},"f:kubectl.kubernetes.io/last-applied-configuration":{}},"f:labels":{".":{},"f:kubernetes.io/metadata.name":{}}}}},{"manager": "kube-controller-manager","operation": "Update","apiVersion": "v1","time": "2022-03-21T09:09:08Z","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":{}}}}}}]
},
"spec": {},
"status": {"phase": "Terminating","conditions": [{"type": "NamespaceDeletionDiscoveryFailure","status": "False","lastTransitionTime": "2022-03-21T09:27:42Z","reason": "ResourcesDiscovered","message": "All resources successfully discovered"},{"type": "NamespaceDeletionGroupVersionParsingFailure","status": "False","lastTransitionTime": "2022-03-21T09:09:08Z","reason": "ParsedGroupVersions","message": "All legacy kube types successfully parsed"},{"type": "NamespaceDeletionContentFailure","status": "False","lastTransitionTime": "2022-03-21T09:23:09Z","reason": "ContentDeleted","message": "All content successfully deleted, may be waiting on finalization"},{"type": "NamespaceContentRemaining","status": "True","lastTransitionTime": "2022-03-21T09:09:08Z","reason": "SomeResourcesRemain","message": "Some resources are remaining: engineimages.longhorn.io has 1 resource instances, nodes.longhorn.io has 3 resource instances"},{"type": "NamespaceFinalizersRemaining","status": "True","lastTransitionTime": "2022-03-21T09:09:08Z","reason": "SomeFinalizersRemain","message": "Some content in the namespace has finalizers remaining: longhorn.io in 4 resource instances"}]
}
}# 执行晚上述操作之后,longhorn-system名称空间就被删除了。
[root@c7u6s5:longhorn]#curl -k -H 'Content-Type: application/json' -XPUT --data-binary @longhorn-system.json http://127.0.0.1:8001/api/v1/namespaces/longhorn-system/finalize
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "Operation cannot be fulfilled on namespaces \"longhorn-system\": StorageError: invalid object, Code: 4, Key: /registry/namespaces/longhorn-system, ResourceVersion: 0, AdditionalErrorMsg: Precondition failed: UID in precondition: 9182f43a-e302-4fe5-b8b4-b37bde46228a, UID in object meta: ",
"reason": "Conflict",
"details": {"name": "longhorn-system","kind": "namespaces"
},
"code": 409
}[root@c7u6s5:longhorn]#kbuectl get ns
-bash: kbuectl: command not found
[root@c7u6s5:longhorn]# kubectl get ns
NAME                   STATUS   AGE
app-team1              Active   175d
default                Active   230d
kube-node-lease        Active   230d
kube-public            Active   230d
kube-system            Active   230d
kubernetes-dashboard   Active   98m
my-ns                  Active   216d
project-snake          Active   167d
[root@c7u6s5:longhorn]# 

上述的curl命令中的@符号后面的是json文件名称。

上述就完成了longhron-system名称空间的删除操作。

http://www.xdnf.cn/news/1253863.html

相关文章:

  • Linux发行版分类与Centos替代品
  • 大数据存储域——HDFS存储系统
  • 进阶向:AI聊天机器人(NLP+DeepSeek API)
  • 【感知机】感知机(perceptron)学习策略
  • Git 乱码文件处理全流程指南:从识别到彻底清除
  • WebView 中控制光标
  • VINS-Fusion+UWB辅助算法高精度实现
  • Pytest项目_day05(requests加入headers)
  • 移动端跨平台框架(支持Harmony、iOS、Android)
  • cacti
  • vue3 find 数组查找方法
  • TrustZone技术详解————这篇是AI写的包括图
  • [Oracle] SIGN()函数
  • 大数据存储域——Hive数据仓库工具
  • 第14届蓝桥杯Scratch_选拔赛_初级及中级(STEMA)真题2022年12月18日
  • 碰撞问题的分析
  • 链式数据结构
  • 基于最大似然估计的卡尔曼滤波与自适应模糊PID控制的单片机实现
  • 北京-4年功能测试2年空窗-报培训班学测开-第六十九天-投简历第一天-从兴奋到害怕
  • 【图像处理基石】浅谈3D城市生成中的数据融合技术
  • 从零开始用 Eclipse 写第一个 Java 程序:HelloWorld 全流程 + 避坑指南
  • 如何设计一个开放授权平台?
  • 用 “私房钱” 类比闭包:为啥它能访问外部变量?
  • 【AI智能编程】Trae-IDE工具学习
  • vector使用模拟实现
  • 排序算法(二)
  • Qt-桌面宠物
  • win10/11网络防火墙阻止网络连接?【图文详解】防火墙阻止连接网络的解决方法
  • Unity 调节 Rigidbody2D 响应速度的解决方案【资料】
  • GPT-OSS-20B vs Qwen3-14B 全面对比测试