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

参考截图


结束

相关推荐
Dillon Dong4 小时前
【系列主题】Next.js 16 + Turbopack 的暗礁:深入剖析 Tailwind v4 的 CSS 模块解析陷阱
javascript·css·容器·turbopack
JellyfishMIX7 小时前
k8s 容器 cpu 概念
docker·容器·kubernetes
梵得儿SHI8 小时前
(第二篇)Spring AI 架构设计与优化:可观察性体系,打造全链路可视化的 AI 运维方案
人工智能·微服务·grafana·prometheus·监控·可观察性·spring ai
BIGmustang9 小时前
基于rancher-rke部署 k8s集群
容器·kubernetes·rancher
Cat_Rocky10 小时前
通过k8s实现单pod部署
java·容器·kubernetes
运维全栈笔记10 小时前
K8S部署WordPress+MySQL:模块化YAML配置详解
服务器·mysql·docker·云原生·容器·kubernetes·服务发现
眷蓝天12 小时前
k8s-pod资源对象实验
云原生·容器·kubernetes·pod资源对象
木雷坞12 小时前
Physical AI 数据工厂怎么落地?先把 CUDA、K8s、Quay 镜像拉取稳定下来
人工智能·容器·kubernetes
剩下了什么13 小时前
docker-compose up -d --build 和 docker-compose up -d 和 docker-compose build 区别
docker·容器·eureka
喜欢流萤吖~13 小时前
消息队列:微服务的异步通信枢纽
微服务·架构