<p>Can someone please explain how POD to POD works in AKS?
from the docs, I can see it uses kube proxy component to send the traffic to the desired POD.</p>
<p>But I have been told that I must use <strong>clusterIP</strong> service and bind all the relevant POD's together.
So what is real flow? Or I missed something. below a couple of questions to be more clear.</p>
<p>Questions:</p>
<ol>
<li>how POD to POD inside one node can talk to each other? what is the flow?</li>
<li>how POD to POD inside a cluster (different nodes) can talk to each other? what is the flow?</li>
<li>if it's possible it will be highly appreciated if you can describe the flows for #1 and #2 in the deployment of kubenet and CNI.</li>
</ol>
<p>Thanks a lot!</p>

monsal
<p>for pod to pod communication we use <code>services</code>. so first we need to understand,</p>
<p><strong>why we need service:</strong> what actually do service for us that, they resolve the dns name and give us the the exact ip that we need to connect a specific pod. now as you want to communicate with pod to pod you need to create a <code>ClusterIP</code> service.</p>
<p><strong>ClusterIP:</strong> Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default ServiceType. with ClusterIP service you can't access a pod from outside the cluster for this reason we use clusterip service if we want the communication between pod to pod only.</p>
<p><strong>kube-proxy</strong> is the network proxy that runs on each node in your cluster.</p>
<p>it maintains network rules on nodes. These network rules allow network communication to your Pods from network sessions inside or outside of your cluster.
every service maintain iptables.And  kube-proxy handled these ip tables for every service. so yes, kube-proxy  is the most vital point for network setup in our k8s cluster.</p>
<p>how the network policy works in kubernetes:</p>
<ul>
<li>all Pods can communicate with all other Pods without using network address translation (NAT).</li>
<li>all Nodes can communicate with all Pods without NAT.</li>
<li>the IP that a Pod sees itself as is the same IP that others see it as.</li>
</ul>
<p>with those point:</p>
<ul>
<li>Container-to-Container networking</li>
<li>Pod-to-Pod networking</li>
<li>Pod-to-Service networking</li>
<li>Internet-to-Service networking</li>
</ul>
<p>It handles transmission of packets between pod to pods, and also with the outside world. It acts like a network proxy and load balancer for pods running on the node by implementing  load-balancing using <code>NAT</code> in <code>iptables</code>.</p>
<p>The kube-proxy process stands in between the Kubernetes network and the pods that are running on that particular node. It is responsible for ensuring that communication is maintained efficiently across all elements of the cluster. When a user creates a Kubernetes service object, the kube-proxy instance is responsible to translate that object into meaningful rules in the local <code>iptables</code> rule set on the worker node. iptables is used to translate the virtual IP assigned to the service object to all of the pod IPs mapped by the service.
i hope it's clear your idea about kube proxy.</p>
<p>lets see a example how it's works.
here i used <code>headless service</code> so that i can connect a specific pod.</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: default
spec:
  clusterIP: None
  selector:
    app: my-test
  ports:
  - port: 80
    name: rest
---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-sts
spec:
  serviceName:  my-service
  replicas: 3
  selector:
    matchLabels:
      app: my-test
  template:
    metadata:
      labels:
        app: my-test
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
              name: web

---
</code></pre>
<p>this will create 3 pods. as : <code>my-sts-0</code>, <code>my-sts-1</code>, <code>my-sts-2</code>. now if we want to connect to the pod <code>my-sts-0</code> just use this dns name <code>my-sts-0.my-service.default.svc:80</code> . and the service will resolve the dns name and will provide the exact podip of <code>my-sts-0</code>. now if you need to comminucate from <code>my-sts-1</code> to <code>my-sts-0</code>, you can just use this dns name.</p>
<p>The template is like <code>my_pod_name.my_Service_Name.my_Namespace.svc.cluster-domain.example</code> , but you can skip the cluster-domain.example part. Only <code>Service_Name.Namespace.svc</code> will work fine.</p>
<p><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">ref</a></p>
