docker环境下通过进程PID查询POD的几种方法

通过进程PID查询POD的几种方法

微信截图_20230802154305.png

1.通过mountinfo获取容器ID

cat /proc/14890/mountinfo | grep "etc-hosts"
1332 1310 253:2 /var/lib/kubelet/pods/ad9a35fb-dd31-4551-b267-9e2ff340ac0b/etc-hosts /etc/hosts rw,relatime - xfs /dev/vda2 rw,attr2,inode64,noquota

这个其中ad9a35fb-dd31-4551-b267-9e2ff340ac0b就是容器ID

我们可以直接在该节点使用docker ps命令过滤出来就可以查看到具体POD了

docker ps | grep ad9a35fb

2.通过cgroup获取容器ID

cat /proc/14890/cgroup
11:freezer:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
10:memory:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
9:net_prio,net_cls:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
8:blkio:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
7:cpuset:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
6:cpuacct,cpu:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
5:perf_event:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
4:pids:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
3:hugetlb:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
2:devices:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope
1:name=systemd:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podad9a35fb_dd31_4551_b267_9e2ff340ac0b.slice/docker-3ffb5ddcfd2d84dd46204a3f08bb504bc7b1cde405feaba93f5c27b68f94399a.scope

这其中的ad9a35fb_dd31_4551_b267_9e2ff340ac0b就是容器ID

也可以使用

docker ps | grep ad9a35fb

命令的到最终的POD容器

微信截图_20230802154517.png

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/925.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。