Find PID info for cri-o worker node

Jbn1233
1 min readDec 19, 2022

--

From top output below, what’s pod and namespace of PID 1496378 ?

$ top
top - 07:44:05 up 33 days, 16:59, 1 user, load average: 0.06, 0.17, 0.65
Tasks: 298 total, 1 running, 287 sleeping, 0 stopped, 10 zombie
%Cpu(s): 1.3 us, 1.8 sy, 0.0 ni, 97.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0
MiB Mem : 32164.2 total, 19245.4 free, 7210.3 used, 5708.6 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 28163.7 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAN
3044818 root 20 0 7288100 743348 37508 S 2.0 2.3 10807:03 kubelet
1496378 xadm 20 0 2336832 392920 34856 S 0.0 1.2 7:28.62 mysqld
847 root 20 0 6305616 248856 26752 S 2.0 0.8 3886:47 crio
1494428 root 20 0 2187556 233064 45072 S 0.0 0.7 26:46.82 minio
ps -ef|grep 1496378
xadm 1496378 1496375 0 Dec16 ? 00:07:29 /opt/bitnami/mysql/bin/mysqld --defaults-file=/opt/bitnami/mysql/conf/my.cnf --basedir=/opt/bitnami/mysql --datadir=/bitnami/mysql/data --socket=/opt/bitnami/mysql/tmp/mysql.sock --pid-file=/opt/bitnami/mysql/tmp/mysqld.pid

As you can see PID 1496378 is MySQL server ,but how to link it to kubernetes pod and namespace ? Try this one

#!/bin/bash

if [ -z "$1" ]
then
echo "Usage $0 [PID]"
exit
fi

if ! grep crio /proc/$1/cgroup &>/dev/null
then
echo PID: $1 is not container or PID not found
exit
fi

PODID=$(sudo head -1 /proc/$1/cgroup |awk -F"crio-" {'print $2'})
PODID=${PODID:0:13}
sudo crictl inspect $PODID | jq '.status.labels'
./pidInfo.sh  1496378
{
"io.kubernetes.container.name": "mysql",
"io.kubernetes.pod.name": "x-mysql-0",
"io.kubernetes.pod.namespace": "x-portal",
"io.kubernetes.pod.uid": "50579273-e3f1-479b-a014-2d3a5d13aea7"
}

PS. crictl and jq is needed

That’s all

--

--

Jbn1233
Jbn1233

Written by Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |

No responses yet