5分钟6步强制删除kubernetes NameSpace小技巧
在使用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小技巧的更多相关文章
- MySQL平滑删除数据的小技巧【转】
今天接到一位开发同学的数据操作需求,需求看似很简单,需要执行下面的SQL语句: delete from test_track_log where log_time < '2019-1-7 00: ...
- Redis批量删除key的小技巧,你知道吗?
在使用redis的过程中,经常会遇到要批量删除某种规则的key,但是redis提供了批量查询一类key的命令keys或scan,没有提供批量删除某种规则key的命令,怎么办?看完本文即可,哈哈. 本文 ...
- node的第一步,hello,以及小技巧和CPU使用情况。到底能用几个核心?
安装了啥的就不说了,百度一下有很多. Windows环境.Linux不会,所有就不说了. 1. hello Word node的hello Word很简单,就一行. console.log(&quo ...
- iOS开发时间控件怎么强制24小时制(小技巧)
1)当你的format格式是 NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];[dateFo ...
- k8s强制删除资源
一般强制删除 kubernetes 的资源: kubectl delete <resource> <resourename> --grace-period=0 --force ...
- Kubernetes中强制删除Pod、namespace
Kubernetes中强制删除Pod.namespace 解决方法 可使用kubectl中的强制删除命令 # 删除POD kubectl delete pod PODNAME --force --gr ...
- kubernetes如何强制删除namespace
K8S如何强制删除namespace 先运行kubectl get namespace ingress-nginx -o json > nginx.json,拿到当前namespace描述,然后 ...
- 用kubernetes部署oa 强制删除pod delete
1.[root@pserver88 oa]# cat Dockerfile FROM tomcat RUN rm -rf /usr/local/tomcat/webapps/*ADD ROOT.war ...
- kubernetes namespace Terminating
1.kubectl get namespace annoying-namespace-to-delete -o json > tmp.jsonthen edit tmp.json and rem ...
随机推荐
- TensorFlow从入门到入坑(1)
初识TensorFlow 一.术语潜知 深度学习:深度学习(deep learning)是机器学习的分支,是一种试图使用包含复杂结构或由多重非线性变换构成的多个处理层对数据进行高层抽象的算法. 深度学 ...
- Spring Cloud Alibaba 使用Nacos作为配置管理中心
为什么需要配置中心? 动态配置管理是 Nacos 的三大功能之一,通过动态配置服务,我们可以在所有环境中以集中和动态的方式管理所有应用程序或服务的配置信息. 动态配置中心可以实现配置更新时无需重新部署 ...
- jQuery根据地址获取经纬度
一.HTML部分 1 @*景区位置*@ 2 <tr> 3 <th>景区名称:</th> 4 <td><input class="txt ...
- hdu 5178 pairs(BC第一题,,方法不止一种,,我用lower_bound那种。。。)
题意: X坐标上有n个数.JOHN想知道有多少对数满足:x[a]-x[b]<=k(题意给)[a<b] 思路: 额,,,直接看代码吧,,,, 代码: int T,n,k; int x[100 ...
- linux 内核源代码情景分析——Intel X86 CPU 系列的寻址方式
当我们说一个CPU是"16位"或"32"位时,指的是处理器中"算数逻辑单元"(ALU)的宽度.数据总线通常与ALU具有相同的宽度.当Inte ...
- PWN学习之栈溢出
目录 PWN学习之栈溢出 前言 写bug bug.cpp源码 OD动态调试bug.exe OD调试观察溢出 栈溢出攻击之突破密码验证 x64位栈溢出 PWN学习之栈溢出 前言 我记得我在最开始学编程的 ...
- vue引入elementUI(第三方样式库)
前置: 在已经安装好vue的前提下 ,没有安装vue参考: vue搭建教程 elementUI官网组件使用文档: elementUI使用文档 1.终端直接运行安装命令 npm i element-ui ...
- mysql 禁止外键检查
SET FOREIGN_KEY_CHECKS=0; SET FOREIGN_KEY_CHECKS=1; from: https://stackoverflow.com/a/15501754/80250 ...
- 问题 N: 非洲小孩
题目描述 家住非洲的小孩,都很黑.为什么呢? 第一,他们地处热带,太阳辐射严重. 第二,他们不经常洗澡.(常年缺水,怎么洗澡.) 现在,在一个非洲部落里,他们只有一个地方洗澡,并且,洗澡时间很短,瞬间 ...
- 菜鸡的Java笔记 java数据库编程(JDBC)
java数据库编程(JDBC) 介绍 JDBC 的基本功能 content (内容) 现在几乎所有的项目开发过程之中都不可能离开数据库,所以在java ...