Kubernetes 故障排查手册:Pod 异常状态全解析

K8s 运维中最常见的问题就是 Pod 起不来,本文整理了所有常见异常状态的排查路径。

排查基本命令

# 查看 Pod 状态
kubectl get pod <pod-name> -o wide

# 查看详细事件(最重要的排查入口)
kubectl describe pod <pod-name>

# 查看容器日志
kubectl logs <pod-name> -c <container-name>

# 查看上一次崩溃的日志
kubectl logs <pod-name> --previous

CrashLoopBackOff

容器反复启动失败,K8s 按指数退避重试。

常见原因:

  1. 应用启动报错 → 看 kubectl logs --previous
  2. 配置文件缺失或格式错误
  3. 依赖服务未就绪(数据库、中间件)
  4. 健康检查配置过于严格
# 进入容器调试(如果能短暂启动)
kubectl exec -it <pod-name> -- /bin/sh

# 临时覆盖启动命令排查
kubectl run debug --image=<image> --command -- sleep 3600

OOMKilled

容器内存超出 limits.memory,被内核 OOM Killer 杀掉。

# 查看退出码,137 = OOMKilled
kubectl describe pod <pod-name> | grep -A5 "Last State"

# 查看节点内存压力
kubectl describe node <node-name> | grep -A10 "Conditions"

解决方案:

  • 调大 resources.limits.memory
  • 排查内存泄漏
  • 优化 JVM 堆内存配置(Java 应用)

Pending

Pod 一直处于 Pending,说明调度失败。

kubectl describe pod <pod-name> | grep -A20 "Events"

常见原因:

事件信息原因
Insufficient cpu/memory资源不足,扩容节点
no nodes matched node selectornodeSelector 无匹配节点
had untolerated taint节点有污点,需加 toleration
PVC not bound存储卷未绑定

ImagePullBackOff

镜像拉取失败。

kubectl describe pod <pod-name> | grep -A5 "Failed"
  • 镜像名/tag 写错
  • 私有仓库未配置 imagePullSecrets
  • 节点无法访问镜像仓库(网络/防火墙)

Terminating 卡住

Pod 删除后一直卡在 Terminating。

# 强制删除
kubectl delete pod <pod-name> --force --grace-period=0

通常是 finalizer 未清除或存储卷卸载失败。

实用排查脚本

# 列出所有非 Running 的 Pod
kubectl get pods -A | grep -v Running | grep -v Completed

# 查看最近重启次数多的 Pod
kubectl get pods -A --sort-by='.status.containerStatuses[0].restartCount' | tail -10

掌握这些排查方法,90% 的 Pod 问题都能快速定位。

← 返回文章列表