CrashLoopBackOff
错误信息
后面-off restarting 失败容器
快速摘要
容器开始, crashes, and Kubernetes restarts 它 — 这个 cycle repeats 使用 increasing 后面-off delays.
为什么发生
application crashes on startup due 到配置错误
必需 dependency (数据库, API) 是不 available 当容器开始
liveness probe 是也 aggressive and kills 容器之前它 是 ready
容器's entrypoint command 是不正确
最小示例
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 0 # too aggressivelivenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30 # give time to startliveness probe 开始 immediately (0s delay) and 失败因为 app 是不 ready. fix gives 30 seconds for startup.
如何诊断
检查 Pod 状态:
kubectl 获取 pods— look for CrashLoopBackOffView 容器 logs:
kubectl logs <pod>andkubectl logs <pod> --上一个描述 Pod for 事件:
kubectl 描述 pod <pod>检查如果 dependencies (数据库, 配置) 是 available and accessible
如何修复
Fix underlying application 错误 shown in logs
Ensure dependencies 是 available 之前容器开始 (use init 容器)
Increase liveness probe's initialDelaySeconds 到 give 更多 startup 时间
Fix entrypoint command in Dockerfile or Pod spec
如何预防
Use init 容器到 wait for dependencies
设置 appropriate liveness probe delays for 慢-开始 applications
测试容器 locally 之前 deploying