Kubernet查找pods不断重启原因
1、describe pod的详细信息,发现有如下Evnets
# kubectl describe pod test-monitor-0 -n promethus
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Created 11m (x26 over 13h) kubelet Created container repl-monitorNormal Started 11m (x26 over 13h) kubelet Started container repl-monitorNormal Pulled 11m (x25 over 13h) kubelet Container image "111111111111.dkr.ecr.ap-southeast-2.amazonaws.com/test-monitor:1875dc6" already present on machine
2、查看 Pod 最近一次崩溃的退出码
# kubectl get pod test-monitor-0 -n repl -o json | jq '.status.containerStatuses[].lastState'"lastState": {"terminated": {"containerID": "containerd://5a2cfcac19be6d2f5779856e007511a6cb8a3146dc936047f41a09e4a663172f","exitCode": 137,"finishedAt": "2025-04-25T02:30:06Z","reason": "OOMKilled","startedAt": "2025-04-25T02:00:05Z"}},
存在关键字段
关键字段是:
exitCode: 退出码(如 137 表示被 OOM Killer 杀死)
reason: OOMKilled, Error, Completed 等
- 查看容器上一次崩溃前的日志
# kubectl logs test-monitor-0 -n prometheus --previous
这会打印上一次崩溃前容器的日志,常能看出是崩溃、panic、内存等问题。
我的实际例子:
1)多次重复日志:
duplicate definition - FailToCallActor()
这个信息连续出现了很多次,可能是某个模块在加载时重复注册了函数,但它本身一般不会导致 crash,除非这个重复引起了异常行为。
2) 多次出现:
unknown modifier: ;
这个比较异常,很可能出现在解析合约参数或执行某个字符串时失败,比如合约 ABI 解析错误、Solidity modifier 写法不当,或者是某个表达式被错误拼接。这可能是导致逻辑错误的地方。
3)多次出现:
gasPrice is too high
说明你代码中有判断 gasPrice 的逻辑,并因此跳过或终止了某些交易。如果这个判断不是优雅处理,而是直接 throw 了异常,有可能造成容器 crash。
3、检查 Pod 或 StatefulSet 中是否设置了 resources.limits.memory:
kubectl get statefulset test-monitor-0 -n prometheus -o yaml | grep -A5 'resources:'
如果设得过低,比如只有几百 Mi,可能因为内存不够而频繁被 kubelet 杀掉。
4、如果日志中还是看不出问题
继续排查:
是否为应用内部崩溃(建议应用层打日志)
是否为健康检查失败(如 Liveness probe 超时导致重启)
kubectl describe pod test-monitor-0 -n prometheus | grep -i 'liveness'