<p>How does pods get unique IP addresses even if they reside in the same worker node?</p>

<p>Also pod is not a device what is logic behind having it an IP address?<br>
Is the IP address assigned to a pod a virtual IP?  </p>

unmesh_swar
<p>A <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/" rel="noreferrer">pod</a> is part of a cluster (group of nodes), and <a href="https://kubernetes.io/docs/concepts/cluster-administration/networking/" rel="noreferrer">cluster networking</a> tells you that:</p>

<blockquote>
  <p>In reality, Kubernetes applies IP addresses at the Pod scope - containers within a Pod share their network namespaces - including their IP address. </p>
  
  <p>This means that containers within a Pod can all reach each other’s ports on localhost.<br>
  This does imply that containers within a Pod must coordinate port usage, but this is no different than processes in a VM.<br>
  This is called the <strong>“IP-per-pod” model</strong>.</p>
</blockquote>

<p>The constraints are:</p>

<blockquote>
  <ul>
  <li>all containers can communicate with all other containers without NAT</li>
  <li>all nodes can communicate with all containers (and vice-versa) without NAT</li>
  <li>the IP that a container sees itself as is the same IP that others see it as</li>
  </ul>
</blockquote>

<p>See more with "<a href="https://medium.com/practo-engineering/networking-with-kubernetes-1-3db116ad3c98" rel="noreferrer"><strong>Networking with Kubernetes</strong></a>" from <a href="https://twitter.com/alsingh87" rel="noreferrer"><strong>Alok Kumar Singh</strong></a>:</p>

<p><a href="https://i.stack.imgur.com/O62bV.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/O62bV.gif" alt="https://cdn-images-1.medium.com/max/1000/1*lAfpMbHRf266utcd4xmLjQ.gif"></a></p>

<p>Here:</p>

<blockquote>
  <p>We have a machine, it is called a <strong>node</strong> in kubernetes.<br>
  It has an IP 172.31.102.105 belonging to a subnet having CIDR 172.31.102.0/24.</p>
</blockquote>

<p>(<a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" rel="noreferrer">CIDR: Classless Inter-Domain Routing</a>, a method for allocating IP addresses and IP routing)</p>

<blockquote>
  <p>The node has an network interface <code>eth0</code> attached. It belongs to root network namespace of the node.<br>
  For pods to be isolated, they were created in their own network namespaces — these are pod1 n/w ns and pod2 n/w ns.<br>
  The pods are assigned IP addresses 100.96.243.7 and 100.96.243.8 from the CIDR range 100.96.0.0/11.</p>
</blockquote>

<p>For the, see "<a href="https://cloudnativelabs.github.io/post/2017-04-18-kubernetes-networking/" rel="noreferrer"><strong>Kubernetes Networking</strong></a>" from <a href="https://twitter.com/cloudnativelabs" rel="noreferrer"><strong>CloudNativelabs</strong></a>:</p>

<blockquote>
  <p>Kubernetes does not orchestrate setting up the network and offloads the job to the <strong><a href="https://github.com/containernetworking/cni" rel="noreferrer">CNI (Container Network Interface)</a></strong> plug-ins. Please refer to the <strong><a href="https://github.com/containernetworking/cni/blob/master/SPEC.md" rel="noreferrer">CNI spec</a></strong> for further details on CNI specification. </p>
  
  <p>Below are possible network implementation options through CNI plugins which permits pod-to-pod communication honoring the Kubernetes requirements:</p>
  
  <ul>
  <li>layer 2 (switching) solution</li>
  <li>layer 3 (routing) solution</li>
  <li>overlay solutions</li>
  </ul>
</blockquote>

<h2>layer 2 (switching)</h2>

<p><a href="https://i.stack.imgur.com/VYSiH.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/VYSiH.jpg" alt="https://cloudnativelabs.github.io/img/l2-network.jpg"></a></p>

<p>You can see their IP attributed as part of a container subnet address range.</p>

<h2>layer 3 (routing)</h2>

<p><a href="https://i.stack.imgur.com/Vkt6G.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Vkt6G.jpg" alt="https://cloudnativelabs.github.io/img/l3-gateway-routing.jpg"></a></p>

<p>This is about populating the default gateway router with routes for the subnet as shown in the diagram.<br>
Routes to 10.1.1.0/24 and 10.1.2.0/24 are configured to be through node1 and node2 respectively. </p>

<h2>overlay solutions</h2>

<p>Generally not used.</p>

<p>Note: See also (Oct. 2018): "<a href="https://cloud.google.com/kubernetes-engine/docs/concepts/network-overview" rel="noreferrer">Google Kubernetes Engine networking</a>".</p>
