<p>Small question regarding Kubernetes and how one pod can talk to another pod (two pods in total) when they are in one same namespace, hopefully without a very complex solution.</p>
<p>Setup:
I have one pod A, called juliette-waiting-for-romeo-tocall, which exposes a rest endpoint <code>/romeo-please-call-me</code></p>
<p>Then, I have a second pod B, called romeo-wants-to-call-juliette, which codes does nothing but trying to make a call to juliette on the endpoint /romeo-please-call-me.</p>
<p>The pod juliette-waiting-for-romeo-tocall is not a complex pod exposed for the internet. This pod does not want any public internet call, does not want any other cluster to call, does not want any pods from different namespace to call. Juliette just want her Romeo which should be on the same namespace to call her.</p>
<p>Nonetheless, Romeo and Juliette are not yet engaged, they are not within one same pod, they don't use the side car pattern, does not share any volume, etc... They are really just two different pods under one same namespace so far.</p>
<p>What would be the easiest solution for Romeo to call Juliette please?</p>
<p>When I do <code>kubectl get all</code>, I do see:</p>
<pre><code>NAME                                             READY   STATUS    RESTARTS   AGE
pod/juliette-waiting-for-romeo-tocall-7cc8b84cc4-xw9n7   1/1     Running   0          2d
pod/romeo-wants-to-call-juliette-7c765f6987-rsqp5         1/1     Running   0          1d

service/juliette-waiting-for-romeo-tocall        ClusterIP      111.111.111.111   &lt;none&gt;          80/TCP            2d
service/romeo-wants-to-call-juliette         ClusterIP      222.222.22.22     &lt;none&gt;          80/TCP            1d
</code></pre>
<p>So far, In Romeo's code, I tried a curl on the cluster IP address + port (in this fake example 111.111.111.111:80/romeo-please-call-me) But I am not getting anything back</p>
<p>What is the easier solution please?</p>
<p>Thank you</p>

PatPanda
<p>More generally, pod-to-pod communication is documented by &quot;<a href="https://kubernetes.io/docs/concepts/cluster-administration/networking/" rel="nofollow noreferrer">Cluster Networking</a>&quot;</p>
<blockquote>
<p>Every Pod gets its own IP address.</p>
<p>This means you do not need to explicitly create links between Pods and you almost never need to deal with mapping container ports to host ports.</p>
<p>This creates a clean, backwards-compatible model where Pods can be treated much like VMs or physical hosts from the perspectives of port allocation, naming, service discovery, load balancing, application configuration, and migration.</p>
<p>Kubernetes imposes the following fundamental requirements on any networking implementation (barring any intentional network segmentation policies):</p>
<ul>
<li>pods on a node can communicate with all pods on all nodes without NAT</li>
</ul>
</blockquote>
<ul>
<li>agents on a node (e.g. system daemons, kubelet) can communicate with all pods on that node</li>
</ul>
<blockquote>
<p>Kubernetes IP addresses exist at the Pod scope - containers within a Pod share their network namespaces - including their IP address and MAC address.</p>
<p>This means that containers within a Pod can all reach each other's ports on localhost.<br />
This also means that containers within a Pod must coordinate port usage, but this is no different from processes in a VM. This is called the &quot;IP-per-pod&quot; model.</p>
</blockquote>
<p>But that depends on which <a href="https://github.com/containernetworking/cni" rel="nofollow noreferrer">CNI (Container Network Interface)</a> has been used for your Kubernetes.</p>
<p>The <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/network/networking.md#pod-to-pod" rel="nofollow noreferrer">Kubernetes Networking design document</a> mentions for pod-to-pod:</p>
<blockquote>
<p>Because every pod gets a &quot;real&quot; (not machine-private) IP address, pods can communicate without proxies or translations.<br />
The pod can use well-known port numbers and can avoid the use of higher-level service discovery systems like DNS-SD, Consul, or Etcd.</p>
<p>When any container calls ioctl(SIOCGIFADDR) (get the address of an interface), it sees the same IP that any peer container would see them coming from — each pod has its own IP address that other pods can know.</p>
<p>By making IP addresses and ports the same both inside and outside the pods, we create a NAT-less, flat address space.<br />
Running &quot;<code>ip addr show</code>&quot; should work as expected.<br />
This would enable all existing naming/discovery mechanisms to work out of the box, including self-registration mechanisms and applications that distribute IP addresses. We should be optimizing for inter-pod network communication. Within a pod, containers are more likely to use communication through volumes (e.g., tmpfs) or IPC.</p>
</blockquote>
<hr />
<p>You can follow the <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/" rel="nofollow noreferrer">Debug Services</a> to troubleshoot this communication issue:</p>
<ul>
<li><p>Does the Service exist?</p>
<pre><code>kubectl get svc hostnames
</code></pre>
</li>
<li><p>Does the Service work by DNS name?</p>
<pre><code>nslookup hostnames
</code></pre>
</li>
<li><p>Does any Service work by DNS name?</p>
<pre><code>nslookup kubernetes.default
</code></pre>
</li>
<li><p>Does the Service work by IP?<br />
Assuming you have confirmed that DNS works, the next thing to test is whether your Service works by its IP address.<br />
From a Pod in your cluster, access the Service's IP (from kubectl get above).</p>
<pre><code>for i in $(seq 1 3); do 
    wget -qO- 10.0.1.175:80
done
</code></pre>
</li>
<li><p>Is the Service defined correctly?</p>
<pre><code>kubectl get service hostnames -o json
</code></pre>
</li>
<li><p>Does the Service have any Endpoints?</p>
<pre><code>kubectl get pods -l app=hostnames
</code></pre>
</li>
<li><p>Are the Pods working?<br />
From within a Pod:</p>
<pre><code>for ep in 10.244.0.5:9376 10.244.0.6:9376 10.244.0.7:9376; do
    wget -qO- $ep
done
</code></pre>
</li>
<li><p>Is the kube-proxy working?</p>
<pre><code>ps auxw | grep kube-proxy
iptables-save | grep hostnames
</code></pre>
</li>
<li><p>Is kube-proxy proxying?</p>
<pre><code>curl 10.0.1.175:80
</code></pre>
</li>
<li><p>Edge case: A Pod fails to reach itself via the Service IP</p>
</li>
</ul>
<blockquote>
<p>This might sound unlikely, but it does happen and it is supposed to work.</p>
<p>This can happen when the network is not properly configured for &quot;hairpin&quot; traffic, usually when kube-proxy is running in iptables mode and Pods are connected with bridge network.<br />
The Kubelet exposes a hairpin-mode flag that allows endpoints of a Service to loadbalance back to themselves if they try to access their own Service VIP.<br />
The hairpin-mode flag must either be set to <code>hairpin-veth</code> or <code>promiscuous-bridge</code>.</p>
</blockquote>
