Operations 9 min read

How to Quickly Map Kubernetes Pods to Host PIDs and Vice Versa

This guide shows Kubernetes operators step‑by‑step how to locate the host process ID of a pod and, conversely, how to identify the pod name from a given PID using kubectl and crictl commands, helping troubleshoot resource spikes in complex clusters.

Linux Ops Smart Journey
Linux Ops Smart Journey
Linux Ops Smart Journey
How to Quickly Map Kubernetes Pods to Host PIDs and Vice Versa

Scenario

As a Kubernetes operator you may notice a CPU‑hungry process on a node and need to know which pod is responsible, or you might see an abnormal pod name in logs and want to find its host PID for debugging.

Environment

The cluster runs Kubernetes v1.27.16 with containerd 1.6.34 on CentOS 7 nodes.

$ k get nodes -owide
NAME          STATUS                     ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE            KERNEL-VERSION               CONTAINER-RUNTIME
k8s-master01  Ready,SchedulingDisabled   control-plane   332d  v1.27.16  172.139.20.121 <none>        CentOS Linux 7 (Core) 5.4.278-1.el7.elrepo.x86_64 containerd://1.6.34
... (other nodes omitted for brevity)

Find Pod PID

1. Identify the node where the pod runs:

$ kubectl -n obs-system get pod logstash-2 -owide
NAME        READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
logstash-2  1/1     Running   1 (87m ago) 17h   10.244.85.210 k8s-node01 <none>          <none>

2. SSH into the node and locate the container ID:

$ sudo crictl ps | grep logstash-2
8aa6be7dedbf2   dd4291c803f45   About an hour ago   Running   logstash   ...   logstash-2

3. Inspect the container to get its PID:

$ sudo crictl inspect 8aa6be7dedbf2 | grep -i pid
"pid": 7474,
"pid": 1,
"type": "pid"

4. Verify the process on the host:

$ ps -ef | grep 7474
ops 7474 7273 6 14:47 ? 00:06:15 /usr/share/logstash/jdk/bin/java ...

Find Pod Name from PID

Given a host PID (e.g., 19398), first view its cgroup information (image omitted).

Then use the container ID (first 13 characters are sufficient) to locate the pod:

$ sudo crictl ps | grep 9c0e370211666
9c0e370211666   3e3e8602ebb26   2 hours ago   Running   sidekiq   ...   gitlab-sidekiq-all-in-1-v2-5875c6bdcb-54lpw

Conclusion

Understanding the mapping between pods and host PIDs is essential for effective Kubernetes troubleshooting; mastering these commands lets operators quickly pinpoint resource‑intensive workloads and demonstrate deep expertise in cloud‑native environments.

cloud-nativecrictlPodPID
Linux Ops Smart Journey
Written by

Linux Ops Smart Journey

The operations journey never stops—pursuing excellence endlessly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.