我如何获得在容器中运行的进程的主机pid?

问题描述 投票:0回答:1

我的容器在kubernetes中运行,我从kubernetes节点日志中看到了很多OOM。所有日志仅具有进程ID信息。很难挖掘OOM的容器。我不知道如何通过主机进程ID查找容器ID。

有什么办法可以在容器内获取主机进程ID,以便获得映射。

这是节点日志

2020-04-28 09:27:15.530 HKT
I0428 01:27:15.530763 1627 log_monitor.go:115] New status generated: &{Source:kernel-monitor Events:[{Severity:warn Timestamp:2020-04-28 01:27:08.060896434 +0000 UTC m=+89600.088785273 Reason:OOMKilling Message:Memory cgroup out of memory: Kill process 2493556 (node) score 1432 or sacrifice child

2020-04-28 09:29:15.000 HKT
Memory cgroup out of memory: Kill process 2493562 (node) score 1529 or sacrifice child Killed process 2493562 (node) total-vm:14009952kB, anon-rss:3146688kB, file-rss:28720kB, shmem-rss:0kB

2020-04-28 09:29:15.000 HKT
Memory cgroup out of memory: Kill process 2496433 (node) score 1275 or sacrifice child Killed process 2496433 (node) total-vm:7183684kB, anon-rss:1833580kB, file-rss:28804kB, shmem-rss:0kB

2020-04-28 09:29:15.309 HKT
I0428 01:29:15.309829 1627 log_monitor.go:115] New status generated: &{Source:kernel-monitor Events:[{Severity:warn Timestamp:2020-04-28 01:29:07.829961434 +0000 UTC m=+89719.857850273 Reason:OOMKilling Message:Memory cgroup out of memory: Kill process 2493562 (node) score 1529 or sacrifice child

2020-04-28 09:29:15.330 HKT
I0428 01:29:15.329925 1627 log_monitor.go:115] New status generated: &{Source:kernel-monitor Events:[{Severity:warn Timestamp:2020-04-28 01:29:07.849907434 +0000 UTC m=+89719.877796273 Reason:OOMKilling Message:Memory cgroup out of memory: Kill process 2496433 (node) score 1275 or sacrifice child

2020-04-28 09:48:29.000 HKT
Memory cgroup out of memory: Kill process 3086395 (monitor) score 237 or sacrifice child Killed process 3086395 (monitor) total-vm:130128kB, anon-rss:9204kB, file-rss:15488kB, shmem-rss:0kB

docker kubernetes containers out-of-memory cgroups
1个回答
0
投票

[好吧,这是我的设计错误。我建议使用1个容器-1个进程,并使该进程成为主进程(PID 1)。该设计将告诉您哪个容器有问题,因为一旦进程达到内存限制,Kubernetes就会重新启动容器。无论如何,使用Kubernetes,您应该使用kubectl get pods查看哪个Pod已重新启动,并查看错误启动的Pod或重新启动计数器的增量。如果您只想使用节点日志(我不建议您使用它),则可能会发现此解决方案可以为您提供帮助CoreOS - get docker container name by PID?

© www.soinside.com 2019 - 2024. All rights reserved.