0

I am writing a script that gathers information about containers running within kubernetes that utilize network namespaces to write a CSV with the following information: "Network Namespace", "Network IP", "Protocol", "Local address", "Remote address", "Status", "PID", "Program name"

The problem I am running into is I can easily gather the pids running within a network namespace utilizing "ip netns pids " but can't figure out a way to get the same information for the host itself. Any insight would be helpful!

5
  • It's common to "create" a name for the host network namespace by doing, say, ln -s /proc/1/ns/net /var/run/netns/default, then you can do ip netns pids default Commented May 28 at 16:11
  • Oh wow thats an awesome easy way to get what I'm looking for thank you! Commented May 28 at 16:35
  • FWIW, you can ask what namespace any PID is in with ip netns identify PID. But by default there isn't a name for the "general" namespace; ip netns identify 1 returns the empty string. You can name it, similar to @muru's command it you want to access it by name. Commented May 28 at 16:40
  • Yes so what I was doing is identifying the PIDs within the namespace so I could reference them back to the starting PID I gathered from crictl inspect that way I could tie Pod, Container, and Container Image together. This is all for IA documentation as they wanted to see the pieces as they were in use in the system and be able to verify dataflow. Commented May 28 at 16:48
  • ls -l /proc/*/ns/net will tell you what namespace each PID is in, so you could correlate that data, even if the namespace doesn't have a name. I know docker namespaces are unnamed by default. Commented May 28 at 17:00

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.