在使用kubernetes过程中,我们经常会遇到无法删除NameSpace的情况,但是如果一一去删除NameSpace中资源比较麻烦。下面我们给大家介绍强制删除NameSpace的方法。

一、查看已存在的NameSpace

$ kubectl get ns
NAME STATUS AGE
default Active 56d
ingress-nginx Active 49d
istio-system Terminating 37d
kube-node-lease Active 56d
kube-public Active 56d
kube-system Active 56d

二、获取需要强制删除的NameSpace信息

$  kubectl get namespace istio-system -o json > istio-system.json
$ cat istio-system.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"labels\":{\"istio-injection\":\"disabled\",\"istio-operator-managed\":\"Reconcile\",\"operator.istio.io/component\":\"Base\",\"operator.istio.io/managed\":\"Reconcile\",\"operator.istio.io/version\":\"1.4.3\"},\"name\":\"istio-system\"}}\n"
},
"creationTimestamp": "2020-01-27T15:26:48Z",
"deletionTimestamp": "2020-02-15T01:17:05Z",
"labels": {
"istio-injection": "disabled",
"istio-operator-managed": "Reconcile",
"operator.istio.io/component": "Base",
"operator.istio.io/managed": "Reconcile",
"operator.istio.io/version": "1.4.3"
},
"name": "istio-system",
"resourceVersion": "6024170",
"selfLink": "/api/v1/namespaces/istio-system",
"uid": "d8bdc915-ee6f-43cd-ac37-5e353218095f"
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"conditions": [
{
"lastTransitionTime": "2020-02-15T01:17:10Z",
"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-02-15T01:17:13Z",
"message": "All legacy kube types successfully parsed",
"reason": "ParsedGroupVersions",
"status": "False",
"type": "NamespaceDeletionGroupVersionParsingFailure"
},
{
"lastTransitionTime": "2020-02-15T01:17:13Z",
"message": "All content successfully deleted, may be waiting on finalization",
"reason": "ContentDeleted",
"status": "False",
"type": "NamespaceDeletionContentFailure"
},
{
"lastTransitionTime": "2020-02-15T01:17:40Z",
"message": "All content successfully removed",
"reason": "ContentRemoved",
"status": "False",
"type": "NamespaceContentRemaining"
},
{
"lastTransitionTime": "2020-02-15T01:17:13Z",
"message": "All content-preserving finalizers finished",
"reason": "ContentHasNoFinalizers",
"status": "False",
"type": "NamespaceFinalizersRemaining"
}
],
"phase": "Terminating"
}
}

三、修改已获取的NameSpace信息文件

示例

$ cat istio-system.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"labels\":{\"istio-injection\":\"disabled\",\"istio-operator-managed\":\"Reconcile\",\"operator.istio.io/component\":\"Base\",\"operator.istio.io/managed\":\"Reconcile\",\"operator.istio.io/version\":\"1.4.3\"},\"name\":\"istio-system\"}}\n"
},
"creationTimestamp": "2020-01-27T15:26:48Z",
"deletionTimestamp": "2020-02-15T01:17:05Z",
"labels": {
"istio-injection": "disabled",
"istio-operator-managed": "Reconcile",
"operator.istio.io/component": "Base",
"operator.istio.io/managed": "Reconcile",
"operator.istio.io/version": "1.4.3"
},
"name": "istio-system",
"resourceVersion": "6024170",
"selfLink": "/api/v1/namespaces/istio-system",
"uid": "d8bdc915-ee6f-43cd-ac37-5e353218095f"
},
"spec": {
},
"status": {
"conditions": [
{
"lastTransitionTime": "2020-02-15T01:17:10Z",
"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-02-15T01:17:13Z",
"message": "All legacy kube types successfully parsed",
"reason": "ParsedGroupVersions",
"status": "False",
"type": "NamespaceDeletionGroupVersionParsingFailure"
},
{
"lastTransitionTime": "2020-02-15T01:17:13Z",
"message": "All content successfully deleted, may be waiting on finalization",
"reason": "ContentDeleted",
"status": "False",
"type": "NamespaceDeletionContentFailure"
},
{
"lastTransitionTime": "2020-02-15T01:17:40Z",
"message": "All content successfully removed",
"reason": "ContentRemoved",
"status": "False",
"type": "NamespaceContentRemaining"
},
{
"lastTransitionTime": "2020-02-15T01:17:13Z",
"message": "All content-preserving finalizers finished",
"reason": "ContentHasNoFinalizers",
"status": "False",
"type": "NamespaceFinalizersRemaining"
}
],
"phase": "Terminating"
}
}

四、运行kube-proxy

$ kubectl proxy
Starting to serve on 127.0.0.1:8001

五、通过API执行强制删除操作

$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @istio-system.json http://127.0.0.1:8001/api/v1/namespaces/istio-system/finalize

六、强制删除确认

$ kubectl get ns
NAME STATUS AGE
default Active 56d
ingress-nginx Active 49d
kube-node-lease Active 56d
kube-public Active 56d
kube-system Active 56d

转载至https://zhuanlan.zhihu.com/p/128599556

5分钟6步强制删除kubernetes NameSpace小技巧的更多相关文章

  1. MySQL平滑删除数据的小技巧【转】

    今天接到一位开发同学的数据操作需求,需求看似很简单,需要执行下面的SQL语句: delete from test_track_log where log_time < '2019-1-7 00: ...

  2. Redis批量删除key的小技巧,你知道吗?

    在使用redis的过程中,经常会遇到要批量删除某种规则的key,但是redis提供了批量查询一类key的命令keys或scan,没有提供批量删除某种规则key的命令,怎么办?看完本文即可,哈哈. 本文 ...

  3. node的第一步,hello,以及小技巧和CPU使用情况。到底能用几个核心?

    安装了啥的就不说了,百度一下有很多. Windows环境.Linux不会,所有就不说了. 1.  hello Word node的hello Word很简单,就一行. console.log(&quo ...

  4. iOS开发时间控件怎么强制24小时制(小技巧)

    1)当你的format格式是 NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];[dateFo ...

  5. k8s强制删除资源

    一般强制删除 kubernetes 的资源: kubectl delete <resource> <resourename> --grace-period=0 --force ...

  6. Kubernetes中强制删除Pod、namespace

    Kubernetes中强制删除Pod.namespace 解决方法 可使用kubectl中的强制删除命令 # 删除POD kubectl delete pod PODNAME --force --gr ...

  7. kubernetes如何强制删除namespace

    K8S如何强制删除namespace 先运行kubectl get namespace ingress-nginx -o json > nginx.json,拿到当前namespace描述,然后 ...

  8. 用kubernetes部署oa 强制删除pod delete

    1.[root@pserver88 oa]# cat Dockerfile FROM tomcat RUN rm -rf /usr/local/tomcat/webapps/*ADD ROOT.war ...

  9. kubernetes namespace Terminating

    1.kubectl get namespace annoying-namespace-to-delete -o json > tmp.jsonthen edit tmp.json and rem ...

随机推荐

  1. 集合先从ArrayList开始

    本篇文章非常建议直接从经典Demo开始哦~ 一.ArrayList简介 ArrayList 的底层是数组队列,相当于动态数组.与 Java 中的数组相比,它的容量能动态增长.在添加大量元素前,应用程序 ...

  2. git merge远程合并

    当某个分支上的开发工作完成后需要将其合入主分支master 但是在提交合并前我们自己最好做一次衍合,目的是检测是否有冲突的风险,如果有应该在本分支先解决冲突然后在提交合并. 否则解决冲突的工作就全部转 ...

  3. 数组中重复的数字 牛客网 剑指Offer

    数组中重复的数字 牛客网 剑指Offer 题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中 ...

  4. H3C 三层交换基于IP限速

    一.背景 目前百度爬虫爬取业务总是按照自己的性能进行抓取客户数据,从来不考虑客户端的网络承受能力,导致客户端网络带宽超出预算范围,因此在客户端方面针对百度的无限制抓取采取相应的策略. 二.解决方案: ...

  5. linux下测试读写

    1.测/目录所在磁盘的纯写速度: time dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file 2.测/目录所在磁盘的纯读速度: time dd if ...

  6. Ubuntu 安装 mysql 报错 "update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在"

    解决方法: sudo cp /etc/mysql/my.cnf /etc/mysql/mysql.cnf 偷梁换柱-! 如果想更新mysql的源方法如下: wget http://dev.mysql. ...

  7. uni-app APP端隐藏导航栏自定义按钮

    话不多说,上代码 // #ifdef APP-PLUS var webView = this.$mp.page.$getAppWebview(); // 修改buttons webView.setTi ...

  8. Netty数据如何在 pipeline 中流动

    前言 在之前文章中,我们已经了解了pipeline在netty中所处的角色,像是一条流水线,控制着字节流的读写,本文,我们在这个基础上继续深挖pipeline在事件传播 Unsafe对象 顾名思义,u ...

  9. 1. 处理静态资源 2. controller如何接受请求得参数 3. 如何把controller得数据保存到view. 4. 在controller如何完成重定向到指定路径 5. controller返回json数据

    1. 1. 处理静态资源2. controller如何接受请求得参数3. 如何把controller得数据保存到view.4. 在controller如何完成重定向到指定路径5. controller ...

  10. request truncate large response body

    requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read, 512 more ...