在使用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. 2021.9.9考试总结[NOIP模拟50]

    T1 第零题 神秘结论:从一个点满体力到另一个点的复活次数与倒过来相同. 于是预处理出每个点向上走第$2^i$个死亡点的位置,具体实现可以倍增或二分. 每次询问先从两个点同时向上倍增,都转到离$LCA ...

  2. Sharding-JDBC基本使用,整合Springboot实现分库分表,读写分离

    结合上一篇docker部署的mysql主从, 本篇主要讲解SpringBoot项目结合Sharding-JDBC如何实现分库分表.读写分离. 一.Sharding-JDBC介绍 1.这里引用官网上的介 ...

  3. poj 2226 Muddy Fields(最小点覆盖)

    题意: M*N的矩阵,每个格不是*就是#.     *代表水坑,#代表草地. 农民要每次可以用一块宽为1,长不限的木板去铺这个矩阵.要求这块木板不能覆盖草地.木板可以重复覆盖(即一块木板与另一块木板有 ...

  4. 安装与卸载JDK8

    前言:学习Java的第一步需要先配置好JDK环境,而JDK8是目前使用最广泛的JDK版本.本文讲解了如何下载安装和卸载JDK8.以下环境为Windows10 下载JDK安装包 Oracle官网 所有J ...

  5. uni-app使用wx-canvas实现微信小程序上显示地图map和坐标geo

    源码 <template> <view class="echart-box"> <canvas class="ec-canvas" ...

  6. 攻防世界Web之fakebook

    打开题目,得到一个网页,包含一个表格.两个按钮. 习惯性先查看网页源码,但没发现有效信息. <!doctype html> <html lang="ko"> ...

  7. google-chrome 启动报错 nss_util.cc(627)] NSS_VersionCheck("3.26") failed. NSS >= 3.26 is required

    一.错误情况 报错如下: [0807/144244.712736:FATAL:nss_util.cc(627)] NSS_VersionCheck("3.26") failed. ...

  8. SpringBoot2.x异步任务EnableAsync

    1.springboot启动类里面使用@EnableAsync注解开启异步功能 @EnableAsync public class Demo001Application { public static ...

  9. win10 python3.8 wxpython.whl 安装步骤

     wxpython是python开发常用图形用户界面(GUI)工具之一,GUI因其直观便捷,对我们提高开发效率一定帮助.这里介绍一下新版本wxPython 4.0.1的安装过程及注意事项. 第1步:下 ...

  10. js 透明度轮播图

    js 透明度轮播图 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...