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!
ln -s /proc/1/ns/net /var/run/netns/default, then you can doip netns pids defaultip netns identify PID. But by default there isn't a name for the "general" namespace;ip netns identify 1returns the empty string. You can name it, similar to @muru's command it you want to access it by name.ls -l /proc/*/ns/netwill tell you what namespace each PID is in, so you could correlate that data, even if the namespace doesn't have a name. I knowdockernamespaces are unnamed by default.