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

参考截图


结束

相关推荐
白泽talk1 小时前
2个小时1w字| React & Golang 全栈微服务实战
前端·后端·微服务
技术liul3 小时前
Docker Compose和 Kubernetes(k8s)区别
docker·容器·kubernetes
MaCa .BaKa4 小时前
35-疫苗预约管理系统(微服务)
spring boot·redis·微服务·云原生·架构·springcloud
竹木一5406 小时前
Docker拉取镜像代理配置实践与经验分享
经验分享·docker·容器
破 风7 小时前
Docker启动mysql容器时找不到 mysqlx.sock 和 mysqld.sock
mysql·docker·容器
鱼饼6号8 小时前
Jenkins Pipeline 构建 CI/CD 流程
linux·运维·服务器·ci/cd·容器·jenkins
Ares-Wang9 小时前
kubernetes》》k8s》》Heml
云原生·容器·kubernetes
代码拾光10 小时前
微服务之间有哪些调用方式?
微服务·架构设计
容器魔方10 小时前
Bilibili、中电信人工智能科技、商汤科技、联通云等正式加入Volcano社区用户组
云原生·容器·云计算
努力的IT小胖子11 小时前
Docker 镜像下载太慢?手把手教你修改镜像源,速度起飞!
后端·docker·容器