免费公开题库原题 #122 · Troubleshooting
Pod Running 但未 Ready 怎么排查?
现象: Pod 显示 0/1 Running — 容器在运行但始终未进入 Ready 状态,无法接收流量。
与 CrashLoopBackOff 的关键区别: 容器不会崩溃,只是持续无法通过就绪探针检查。
诊断:
# 1. 查看 Pod 状态和探针配置
kubectl describe pod <pod-name>
# 重点关注 "Readiness" 部分和类似事件:
# "Readiness probe failed: HTTP probe failed with statuscode: 503"
# 2. 在 Pod 内部直接测试就绪端点
kubectl exec -it <pod-name> -- curl http://localhost:<port>/health
常见根本原因:
1. 就绪探针路径或端口错误:
readinessProbe:
httpGet:
path: /ready # 必须返回 2xx
port: 8080 # 必须与 containerPort 一致
initialDelaySeconds: 10
periodSeconds: 5
2. 应用启动时间超过 initialDelaySeconds:
- 应用需要 30s 预热但探针 5s 就开始 → 应用就绪前探针就已失败。
- 修复:增大
initialDelaySeconds或使用 startupProbe。
3. 依赖服务未就绪时健康检查返回非 2xx:
- 数据库或依赖服务尚未可用。
- 修复:应用的健康接口应在所有依赖就绪后才返回 200。
4. TCP 探针连接端口错误:
readinessProbe:
tcpSocket:
port: 6379 # 确保应用实际监听此端口
快速验证:
# 检查端口是否监听
kubectl exec <pod-name> -- wget -O- http://localhost:8080/health
kubectl exec <pod-name> -- netstat -tlnp | grep 8080