Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Services and Networking  ›  Lesson

Pod-to-Pod Networking

Networking & Pod-to-Pod Communication 12 minEvery pod has its own IP and can reach every other pod directly without NAT, through a network built by a CNI plugin, but pod IPs change when pods are replaced.

Pod-to-Pod Networking

notes-web must talk to notes-db. They may run on different nodes, in different racks. Before learning Services, you need the simple promise that Kubernetes makes about how pods reach each other.

The rule

Every pod gets its own IP, and every pod can reach every other pod directly.

The Kubernetes network model has a few firm rules:

  • Each pod gets its own IP address, shared by all its containers.
  • Any pod can reach any other pod by its IP, on any node, without NAT (the address the receiver sees is the sender's real pod IP).
  • Agents on a node, such as the kubelet, can reach all pods on that node.
  • Containers inside one pod talk over localhost.

Kubernetes itself does not build this network. A CNI plugin (Container Network Interface) does — for example Calico, Cilium or Flannel. Managed clusters install one for you.

kubectl get pods -n notes -o wide
# NAME          READY   STATUS    IP           NODE
# notes-web-a   1/1     Running   10.244.1.7   node-1
# notes-db-0    1/1     Running   10.244.2.4   node-2

From inside notes-web-a, a connection to 10.244.2.4:5432 reaches Postgres on another node directly.

By default the network is open: every pod may reach every pod. A NetworkPolicy can restrict that — for example "only pods labelled app: notes-web may connect to notes-db on port 5432" — provided the CNI plugin supports policies.

The shortcut

Picture the cluster as one flat office floor: every desk (pod) has a phone number (IP) and can call any other desk directly. The catch: desks move, and numbers change.

notes-web calls notes-db by IPStep 1 of 4
  1. It works

    notes-web connects to 10.244.2.4:5432 and reaches the database on node-2.

The trap is copying a pod IP into configuration. It works on the day you test it and breaks the next time the pod is replaced.

Drills

Answer fast — trust the rule.

quick drill

Two containers in the same pod need to talk. What address do they use?

quick drill

Which component actually builds the pod network?

quick drill

With no NetworkPolicy, can a pod in namespace notes reach a pod in another namespace by IP?

quick drill

Why is hard-coding notes-db's pod IP in notes-web's settings a mistake?

Remember

  • Every pod gets its own IP and can reach every other pod directly, without NAT.
  • One flat office floor — but desks move and numbers change.
  • Trap: hard-coding pod IPs; namespaces alone do not isolate traffic.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainThe flat network

Describe the Kubernetes pod network model and explain why notes-web should not store notes-db's pod IP in its configuration.