<p>In k8s, I want my server to listen on podIP rather than 127.0.0.1 or 0.0.0.0. But the podIP is dynamically allocated, so I want to do something like:</p>
<pre class="lang-golang prettyprint-override"><code>ip := getIPFromNic(&quot;eth0&quot;)
net.Listen(ip)
</code></pre>
<p>But I don't know how to ensure the nic in pod is called eth0 rather than en0 or others. Should I do something in Dockerfile or should I do something in deployment.yaml?</p>
<p>I tried to search on google, but didn't find any related resources about the nic in docker. Most of the blogs are talking about the veth and docker bridge</p>

PHPBird
<ol>
<li>Your pods ip address is present in:
<code>/proc/1/task/1/net/fib_trie</code>
file</li>
</ol>
<p>mine is like:</p>
<pre><code> cat /proc/1/task/1/net/fib_trie
Main:
  +-- 0.0.0.0/1 2 0 2
     +-- 0.0.0.0/4 2 0 2
        |-- 0.0.0.0
           /0 universe UNICAST
        +-- 10.0.0.0/24 2 0 2
           |-- 10.0.0.45
              /32 host LOCAL
           |-- 10.0.0.184
              /32 link UNICAST
     +-- 127.0.0.0/8 2 0 2
        +-- 127.0.0.0/31 1 0 0
           |-- 127.0.0.0
              /32 link BROADCAST
              /8 host LOCAL
           |-- 127.0.0.1
              /32 host LOCAL
        |-- 127.255.255.255
           /32 link BROADCAST
</code></pre>
<p>and 10.0.0.45 is my pod ip address</p>
<hr />
<ol start="2">
<li>also if you have enough privileges, you can use kubernetes rest api to access pod information:</li>
</ol>
<p><code>curl -s -H &quot;Authorization: Bearer $YOUR_TOKEN&quot; https://$KUBERNETES_SERVICE_HOST/api/v1/namespaces/$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)/pods/$(hostname)/ | grep &quot;podIP&quot; | awk '{print $2}' | tr -d '&quot;,'</code></p>
<p>unfortunately default privileges of <code>cat /var/run/secrets/kubernetes.io/serviceaccount/token</code> is not enough for this request.</p>
