OOM Killed
错误信息
容器 died due 到 OOMKilled (exit code 137)
快速摘要
容器 used 更多 memory than 它的配置限制, 所以 kernel killed 它到 protect 系统.
为什么发生
容器's memory 限制是 也低 for application's 需要
application 有 memory leak 那个 causes usage 到 grow over 时间
application 加载大 datasets 到 memory at 一次
否 memory 限制是 设置 and 节点运行 out 的 memory
最小示例
resources:
limits:
memory: 128Mi # too low for the applicationresources:
limits:
memory: 512Mi # increased to match actual usagememory 限制是 也低 (128Mi), causing OOMKilled. fix increases 它到 512Mi 到 match application's 需要.
如何诊断
检查 Pod's exit code:
kubectl 描述 pod <pod>— look for OOMKilledReview memory usage 使用
kubectl 顶部 pod <pod>or Grafana dashboards检查容器's memory 限制 in Pod spec
Use
docker stats到 monitor memory usage in 真实-时间
如何修复
Increase memory 限制 in 容器 spec:
resources.限制.memoryFix memory leaks in application code
Optimize application 到 use 更少 memory (stream 数据相反的 加载所有)
添加 memory 请求 and 限制 based on observed usage 模式
如何预防
设置 appropriate memory 请求 and 限制 based on 加载测试
Monitor memory usage trends and adjust 限制 proactively
Use profiling tools 到 identify memory leaks early