momo's Blog.

Kubernetes 部署时提示 'Failed create pod sandbox'

字数统计: 434阅读时长: 2 min
2021/06/15 Share

前言

在部署容器的时候, Pod提示

1
Failed create pod sandbox: rpc error: code = Unknown desc = failed to create containerd task: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:319: getting the final child's pid from pipe caused \"read init-p: connection reset by peer\"": unknown

原因

在宿主机上, 我们查看/var/log/message 发现有许多OOM的日志

1
2
3
4
5
6
7
8
9
10
11
12
Jun 14 19:56:26 10-11-10-85 kernel: Task in /kubepods/pod7325612f-d0a8-4bda-880c-510bddc9dce8/f03200d29dc96ea14ee5a5f65ae490569c8cfe32b5delled as a result of limit of /kubepods/pod7325612f-d0a8-4bda-880c-510bddc9dce8
Jun 14 19:56:26 10-11-10-85 kernel: memory: usage 0kB, limit 0kB, failcnt 377
Jun 14 19:56:26 10-11-10-85 kernel: memory+swap: usage 0kB, limit 9007199254740988kB, failcnt 0
Jun 14 19:56:26 10-11-10-85 kernel: kmem: usage 0kB, limit 9007199254740988kB, failcnt 0
Jun 14 19:56:26 10-11-10-85 kernel: Memory cgroup stats for /kubepods/pod7325612f-d0a8-4bda-880c-510bddc9dce8: cache:0KB rss:0KB rss_huge:le:0KB dirty:0KB writeback:0KB swap:0KB inactive_anon:0KB active_anon:0KB inactive_file:0KB active_file:0KB unevictable:0KB
Jun 14 19:56:26 10-11-10-85 kernel: Memory cgroup stats for /kubepods/pod7325612f-d0a8-4bda-880c-510bddc9dce8/f03200d29dc96ea14ee5a5f65ae4508487023c483: cache:0KB rss:0KB rss_huge:0KB shmem:0KB mapped_file:0KB dirty:0KB writeback:0KB swap:0KB inactive_anon:0KB active_anon:0KBve_file:0KB unevictable:0KB
Jun 14 19:56:26 10-11-10-85 kernel: Tasks state (memory values in pages):
Jun 14 19:56:26 10-11-10-85 kernel: [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name
Jun 14 19:56:26 10-11-10-85 kernel: [ 294465] 0 294465 5735 995 73728 0 -998 exe
Jun 14 19:56:26 10-11-10-85 kernel: Memory cgroup out of memory: Kill process 294465 (exe) score 1013000 or sacrifice child
Jun 14 19:56:26 10-11-10-85 kernel: Killed process 294465 (exe) total-vm:22940kB, anon-rss:1508kB, file-rss:2472kB, shmem-rss:0kB
Jun 14 19:56:26 10-11-10-85 kernel: oom_reaper: reaped process 294465 (exe), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

我的YAML是这样写的

1
2
3
4
resources:
limits:
cpu: "250m"
memory: "300m"

实际上上面的写法写错了, memory 的单位只能是 E, P, T, G, M, K, Ei, Pi, Ti, Gi, Mi, Ki.

所以我们需要改成

1
2
3
4
resources:
limits:
cpu: "250m"
memory: "300Mi"

参考

  1. manage-resources-containers
  2. Quantity
CATALOG
  1. 1. 前言
  2. 2. 原因
  3. 3. 参考