# Kernel pid for pod / container?

**URL:** <https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426>\
**Category:** General Discussions\
**Created:** [April 6, 2021, 3:01pm UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426 "2021-04-06T15:01:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alessandro\_Dentella](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/alessandro_dentella/32/6541_2.png) [@Alessandro\_Dentella](https://discuss.kubernetes.io/u/Alessandro_Dentella)\
**Post date:** [April 6, 2021, 3:01pm UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426/1 "2021-04-06T15:01:56Z")

</div>

What is the equivalent of:

```auto
docker inspect -f '{{.State.Pid}}' <container id>

```

to get the pid of a Pod -if at all reasonable- or at least the pid of a container?

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [April 6, 2021, 3:26pm UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426/2 "2021-04-06T15:26:04Z")

</div>

A pod is not a running process, so it does not have a PID.

What question are you really trying to solve? 🙂

---

<div class="post-metadata">

**Author:** ![Alessandro\_Dentella](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/alessandro_dentella/32/6541_2.png) [@Alessandro\_Dentella](https://discuss.kubernetes.io/u/Alessandro_Dentella)\
**Post date:** [April 6, 2021, 6:19pm UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426/3 "2021-04-06T18:19:34Z")

</div>

Thanks @thockin, good point. In fact I know a pod is not a process, that’s why I sad “or at least the pid of a container”. The reason is to debug it. When working with docker I really appreciated being able to “nsenter” into the process’s namespace with --net option so that I has all the tools installed on the host, but in the constraint of the network of the container. I find it very useful and effective.  
Now that I’m studying kubernetes I’d like to use the same technique.

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [April 6, 2021, 7:42pm UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426/4 "2021-04-06T19:42:45Z")

</div>

Pedantically, a container doesn’t have a PID either. What you see is the PID of the “root” process in that container.

In Kubernetes you can nsenter the netns of any of the member containers - they are all the same netns. We also have `EphemeralContainers` which seems to still be alpha.

---

<div class="post-metadata">

**Author:** ![Alessandro\_Dentella](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/alessandro_dentella/32/6541_2.png) [@Alessandro\_Dentella](https://discuss.kubernetes.io/u/Alessandro_Dentella)\
**Post date:** [April 7, 2021, 7:24am UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426/5 "2021-04-07T07:24:34Z")

</div>

Thanks again @thockin…

> [@thockin](#):
>
> Pedantically, a container doesn’t have a PID either. What you see is the PID of the “root” process in that container.

ok, that’s what I meant

> [@thockin](#):
>
> In Kubernetes you can nsenter the netns of any of the member containers - they are all the same netns. We also have `EphemeralContainers` which seems to still be alpha.

…mmh… you mean all containers share the same net…? that’s definitely some things I already noted to be studied deeper.

I have a pod that doesn’t reach the database (hosted on the host, not on kubernetes). After adding IP to my docker I realized it has /32 netmask… I would have liked to be able to use tools from the system (as opposed to “tools in the container”) to investigate IP, route and so on.

In pure docker I can nsenter the root process and use “Ip addr ls”: is there an equivalent in kubernetes?

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [April 7, 2021, 3:44pm UTC](https://discuss.kubernetes.io/t/kernel-pid-for-pod-container/15426/6 "2021-04-07T15:44:25Z")

</div>

> you mean all containers share the same net…? that’s definitely some things I already noted to be studied deeper.

That’s right. At least in all of the runtime implementations I know of. 🙂

> I would have liked to be able to use tools from the system (as opposed to “tools in the container”) to investigate IP, route and so on.

This is what Ephemeral Containers is supposed to make better. Sadly it’s not GA yet.

> In pure docker I can nsenter the root process and use “Ip addr ls”: is there an equivalent in kubernetes?

Kubernetes has an abstraction called CRI between kubelet and the container runtime. If you are using a Docker runtime, you can still do this. If you are using a different runtime you might need to figure out how to do it for that runtime, but unless you use something very different, it should be about the same.
