<p>is there anyway to see the relationship of kubernetes v1.15.2 pod and veth? now I could see the veth in host but do not know which pod owned.</p>

<pre><code>vethe4297f4: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1450
        ether ba:01:db:4a:7d:d0  txqueuelen 0  (Ethernet)
        RX packets 9999796  bytes 1671107011 (1.5 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9231477  bytes 2153738950 (2.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethf059d46: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1450
        ether 6a:8f:a3:65:dd:4c  txqueuelen 0  (Ethernet)
        RX packets 11724557  bytes 5581499446 (5.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12847645  bytes 2142367255 (1.9 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethf9efebf: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1450
        ether fa:c7:76:53:4a:36  txqueuelen 0  (Ethernet)
        RX packets 11103657  bytes 2587046474 (2.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8993500  bytes 1816804215 (1.6 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
</code></pre>

<p>by the way, I am learning the flannel communication procedure from the architecture :</p>

<p><a href="https://i.stack.imgur.com/ilGX5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ilGX5.png" alt="enter image description here"></a></p>

<blockquote>
<p>is there anyway to see the relationship of kubernetes v1.15.2 pod and veth?</p>
</blockquote>
<p>TL;DR :
Yes.<br />
There is a <a href="https://stackoverflow.com/questions/21724225">bunch of similar topics</a> on StackOverflow and even some <a href="https://github.com/micahculpepper/dockerveth" rel="nofollow noreferrer">scripts on Github</a>.</p>
<h1>Explanation:</h1>
<p>There is a <a href="https://dustinspecker.com/posts/how-do-kubernetes-and-docker-create-ip-addresses/" rel="nofollow noreferrer"> very good article</a> on Kubernetes (K8s) networking.</p>
<p>Oversimplified, &quot;K8s networking&quot; handled by Linux’s network namespaces and virtual interfaces.</p>
<p>Below console output has been taken on my GKE cluster, but shall be applicable to standalone cluster as well.</p>
<pre><code>$ sudo ip link show | egrep &quot;veth|docker&quot; | awk -F&quot;:&quot; '{print $1&quot;: &quot;$2}'
3:  docker0
5:  vethcf35c1bb@if3
6:  veth287168da@if3
7:  veth5c70f15b@if3
11:  veth62f193f7@if3
12:  vetha38273b3@if3
14:  veth240a8f81@if3

sudo docker ps --format '{{.ID}} {{.Names}} {{.Image}}' &quot;$@&quot;  | wc -l
25
</code></pre>
<p>As you can see, I have 6 <code>veth</code>'s  serving traffic for 25 docker containers. Let's find the <code>veth</code> that serves traffic for one of the pods.</p>
<pre><code>$ kubectl get pods 
NAME                         READY   STATUS    RESTARTS   AGE
server-go-7b57857cfb-p6m62   1/1     Running   0          7m41s
</code></pre>
<ol>
<li>Lets find the docker container id for the pod.</li>
</ol>
<pre><code>$ sudo docker ps --format '{{.ID}} {{.Pid}} {{.Names}} {{.Image}}' &quot;$@&quot; | grep POD_server
6aa1d952a9f3 k8s_POD_server-go-7b57857cfb-p6m62_default_02206a28-42e1-43a5-adb8-f6ab13258fb1_0 k8s.gcr.io/pause:3.1
</code></pre>
<ol start="2">
<li>Checking a <code>pid</code> for it:</li>
</ol>
<pre><code>$ sudo docker inspect --format '{{.State.Pid}}' 6aa1d952a9f3
4012085
</code></pre>
<ol start="3">
<li>Allowing system tools accessing the namespace of that <code>pid</code>:</li>
</ol>
<pre><code>$ sudo ln -sf /proc/${pid}/ns/net /var/run/netns/ns-${pid}
</code></pre>
<pre><code>#in my case the commands were :
$ if [ ! -d /var/run/netns ]; then sudo  mkdir -p /var/run/netns; fi
$ sudo ln -sf /proc/4012085/ns/net /var/run/netns/ns-4012085
</code></pre>
<pre><code>$ sudo ip netns exec &quot;ns-4012085&quot; ip link show type veth | grep &quot;eth0&quot;
3: eth0@if14: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1460 qdisc noqueue state UP mode DEFAULT group default 
</code></pre>
<ol start="4">
<li>Checking  exact interface that serves traffic for the container.</li>
</ol>
<p>From that output (<code>eth0@if14</code>) we can say that the <code>eth0</code> for the <code>6aa1d952a9f3</code> docker container is linked to the interface <code>14:  veth240a8f81@if3</code>  on host machine.</p>
<p>Based on this example you can write your own script to match <code>veth</code> interfaces to Pods, containers, etc.</p>
<p>Hope that helps.</p>
