Summer's Blog
😈酷炫主页
✨运维
🎉安装
👀踩坑
  • k8s
  • shell
  • python
  • redis
  • elasticsearch
  • mysql
  • ceph
  • spark
  • 关于
  • 思维
  • 命令
  • 友链
  • 分类
  • 标签
  • 归档
👨‍👩‍👦‍👦腾讯云社区
🗣GitHub

Summer———夏苏文

💨运维界的前行者
😈酷炫主页
✨运维
🎉安装
👀踩坑
  • k8s
  • shell
  • python
  • redis
  • elasticsearch
  • mysql
  • ceph
  • spark
  • 关于
  • 思维
  • 命令
  • 友链
  • 分类
  • 标签
  • 归档
👨‍👩‍👦‍👦腾讯云社区
🗣GitHub
  • ES只读模式修改
  • mysql主从只读
  • 服务器CPU爆满问题定位
  • 浅谈VIP地址漂移
  • 恢复磁盘占用过大变成只读模式
  • 登录环境故障解决
  • 解决ES无分片可用
  • docker日志过大处理
  • 软连接解决磁盘满
  • k8s常用端口打不开
  • redis端口不通解决方法
  • Docker容器启动报ipv4
  • nginx安装lua模块报错处理
  • linux重启网卡报错处理
  • linux命令notfound处理汇总
  • redis创建集群问题解决
  • k8s容器时间修改
  • k8s无法删除namespace
    • 查看namespace
    • 解决方法一
    • 解决方法二
  • 服务器终端乱码问题
  • getcwd无法定位当前工作目录
  • Citrix设置vm开机自启动
  • 踩坑
summer
2021-02-07

k8s无法删除namespace

kubernetes 删除 namespace 但是一直处于 Terminating 状态

# 查看namespace

  • 这里可以看到之前部署 kubesphere 生成的 namespace 没删掉
[root@master ]# kubectl get ns
NAME                           STATUS        AGE
cattle-logging                 Active        2d20h
cattle-prometheus              Active        2d19h
cattle-system                  Active        2d20h
default                        Active        11d
fleet-system                   Active        2d20h
kspark                         Active        11d
kube-node-lease                Active        11d
kube-public                    Active        11d
kube-system                    Active        11d
kubeapps                       Active        11d
kubesphere-controls-system     Terminating   4d23h
kubesphere-monitoring-system   Terminating   4d23h
monitoring                     Active        4d3h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 解决方法一

  1. 首先导出json格式到xxx.json
[root@master ]# kubectl get namespace kubesphere-controls-system -o json > xxx.json
[root@master ]# kubectl get namespace kubesphere-monitoring-system -o json > yyy.json
[root@master ]# ll
-rw-r--r-- 1 root root  4751 2月   7 14:33 xxx.json
-rw-r--r-- 1 root root  4693 2月   7 14:36 yyy.json
[root@master ]# 
1
2
3
4
5
6
  1. 编辑xxx.josn,yyy.josn删除finalizers 字段的值
"finalizers": [
            "finalizers.kubesphere.io/namespaces"
        ],

#改为


"finalizers": [ ],
1
2
3
4
5
6
7
8
  1. 开启 proxy
[root@master ]# kubectl proxy
Starting to serve on 127.0.0.1:8001

1
2
3
  1. 新开窗口执行
[root@master ]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @xxx.json http://127.0.0.1:8001/api/v1/namespaces/kubesphere-controls-system/finalize
[root@master ]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @yyy.json http://127.0.0.1:8001/api/v1/namespaces/kubesphere-monitoring-system/finalize
[root@master ]#kubectl get ns
NAME                STATUS        AGE
cattle-logging      Active        2d20h
cattle-prometheus   Active        2d20h
cattle-system       Active        2d21h
default             Active        11d
fleet-system        Active        2d20h
kspark              Active        11d
kube-node-lease     Active        11d
kube-public         Active        11d
kube-system         Active        11d
kubeapps            Active        11d
monitoring          Active        4d4h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

原理其实就是将现有状态导出为json文件,再执行覆盖;

# 解决方法二

  • 直接 edit 该资源,将 finalizers 字段的值删除(vim dd)
[root@master ]# kubectl get ns
NAME                STATUS   AGE
cattle-logging      Active   2d21h
cattle-prometheus   Active   2d20h
cattle-system       Active   2d21h
default             Active   11d
fleet-system        Active   2d21h
kspark              Active   11d
kube-node-lease     Active   11d
kube-public         Active   11d
kube-system         Active   11d
kubeapps            Active   11d
monitoring          Active   4d4h
kharbor             Terminating   5d5h
[root@master ]# kubectl edit ns kharbor
namespace/kharbor edited
[root@master ]# kubectl get ns
NAME                STATUS   AGE
cattle-logging      Active   2d21h
cattle-prometheus   Active   2d20h
cattle-system       Active   2d21h
default             Active   11d
fleet-system        Active   2d21h
kspark              Active   11d
kube-node-lease     Active   11d
kube-public         Active   11d
kube-system         Active   11d
kubeapps            Active   11d
monitoring          Active   4d4h
[root@master ]# 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

总结:每当删除 namespace 或 pod 等一些 Kubernetes 资源时,有时资源状态会卡在 Terminating,很长时间无法删除,甚至有时增加 --force flag 之后还是无法正常删除。这时就需要 edit 该资源,将 finalizers 字段设置为 [],之后 Kubernetes 资源就正常删除了。

#K8s
上次更新: 2/7/2021, 4:29:58 PM
k8s容器时间修改
服务器终端乱码问题

← k8s容器时间修改 服务器终端乱码问题→

最近更新
01
Citrix设置vm开机自启动
02-17
02
ntp与chrony时间同步
12-17
03
centos8安装部署ovirt-engine
11-21
更多文章>
Theme by Vdoing | Copyright © 2019-2023 夏苏文 | MIT License

网站已在灾难中运行:

蜀ICP备2022029853号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式