How to match host process pid with pod name ?

Thu 19 August 2021 by admin

When you identify from host perspective the most CPU intensive task you may wonder how to match it with pod name ? It's pretty simple the relation between host pid and pod name is cgroup... more precisely cgroup name. There are multple ways to get cgroup name, one of them is:

# cat /proc/1234/cgroup
...
6:cpu,cpuacct:/kubepods/burstable/podc52a7741-f290-4dde-b6e4-34e623dbc69e/81591f675f72cfbb3da4156bd2adc0067d54c87eec36a59cce964a4861c083f0
...

It means that kubelet is using cgroupfs to deal with setting cgroup for containers and other option is to use systemd cgroup driver. The second option sounds better because now we have only one cgroup manager to setting resources. Back to the example how to identify each part of this cgroup name. First part kubepods seems to be a constant variable, the second part identify QoS, the third option the most interesting is pod UID and last seems to container id. So having pod UID, we can get pod name just by filtering pod list from all namespaces:

$ kubectl get pods -A -o=custom-columns=NAME:.metadata.name,NS:.metadata.namespace,UID:.metadata.uid | grep c52a7741-f290-4dde-b6e4-34e623dbc69e

Comments