K8S容器持续Terminating无法正常关闭(sider-car容器异常,微服务容器正常)

问题

K8S上出现大量持续terminating的Pod,无法通过常规命令删除。需要编写脚本批量强制删除持续temminating的Pod:contribution-xxxxxxx。

解决

  1. 获取terminating状态的pod名称的命令:
bash 复制代码
# 获取media命名空间下,名称带contribution,运行状态除了正常Runing的Pod信息,并只打印第一列Pod名称。
kubectl get pod -n media |grep contribution|grep -v Running|awk '{print $1}'
  1. 强制删除pod的命令:
bash 复制代码
# 强制删除media命令空间下,名为 contribution-7d57bdb6d7-krksf的Pod。
kubectl delete pods contribution-7d57bdb6d7-krksf --grace-period=0 --force -n media
  1. 编写脚本对大量terminating的同名容器强制删除:
bash 复制代码
vim 72_ForceDeleteTerminatingPods.sh

脚本具体内容如下:

bash 复制代码
#!/bin/bash
for POD in `kubectl get pod -n media |grep contribution|grep -v Running|awk '{print $1}'`
do
    kubectl delete pods ${POD} --grace-period=0 --force -n media
done
  1. 执行结果
bash 复制代码
[sysma@prod-k8s-0001 ~]$ chmod +x 72_ForceDeleteTerminatingPods.sh 
[sysma@prod-k8s-0001 ~]$ ./72_ForceDeleteTerminatingPods.sh 
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-56695dbc4-dq2bc" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-58c5f57b54-wkkfs" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-5f646dd579-tjcf2" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-7499fc9b64-2v8tm" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-75d5f4c94c-q42hq" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-76d45d4bcb-5wtsr" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-784b5569b7-ggdx9" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-7d57bdb6d7-krksf" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-7d57bdb6d7-qjn4w" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-7ff99c7d9d-8p6bf" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-7ff99c7d9d-vfg72" force deleted
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "contribution-b69bb846d-trwx2" force deleted

参考截图


结束

相关推荐
梦想的颜色16 小时前
硬核|Docker从入门到精通:镜像构建、仓库推送、Compose编排、生产部署全攻略
运维·服务器·docker·容器·部署·环境·镜像
zz07232016 小时前
深入理解Seata:微服务分布式事务解决方案
微服务·seata·分布式事务
SXJR17 小时前
使用docker 部署向量数据库Milvus
数据库·docker·容器·milvus·向量数据库
qq_4523962317 小时前
第二篇:《K8s 集群搭建:Minikube、kubeadm、Kind 对比与实操》
容器·kubernetes·kind
jingqiulyue18 小时前
docker run出现exited或者不断restart怎么办
docker·容器
小哈里18 小时前
【K8S】OCI标准下的企业级镜像治理:Harbor+Skopeo+Trivy 最佳实践
云原生·容器·kubernetes·harbor·镜像·skopen
花间相见18 小时前
【Kubernetes02】—— 使用 kubeadm 从零搭建 K8s 集群(实操避坑版)
云原生·容器·kubernetes
人工智能培训18 小时前
从GPT到开源大模型
人工智能·gpt·深度学习·机器学习·容器·知识图谱
许彰午18 小时前
微服务安全上下文的透明传递——ThreadLocal透传与HTTP头转发的完整链路
安全·http·微服务
张小凡vip18 小时前
Kubernetes--secret的简介和使用
云原生·容器·kubernetes