Pod networking and CNI
Follow a request between Pods
Kubernetes networking lets ordinary Pods communicate using IP addresses without manually publishing every container port. In our bookstore, the shop calls the inventory API even when the two Pods run on different worker nodes. A Service supplies a stable destination while the Pod network transports traffic to the selected backend. This chapter separates those responsibilities. The examples describe a fictional IPv4 Linux cluster; they are not deployment instructions.
One Pod has a shared network namespace
A network namespace holds interfaces, routes and socket bindings. Containers in an ordinary Pod share that network namespace: a companion can reach an app listening on localhost:8080, but two processes cannot independently bind the same address, protocol and port without appropriate socket sharing. Another Pod has a separate network namespace, so its localhost points back to itself. Use a Pod IP or a Service to reach another Pod. Host-networked workloads are a special case and are outside this fixture. A Pod replacement may receive a different IP; never use its IP as a permanent application identity.
Synthetic logical paths (not packet captures)Same Pod: app -> localhost:8080 -> companion (same network namespace)Same node: shop 10.42.1.10 -> local forwarding -> cache 10.42.1.11Cross node: shop -> node-a forwarding -> underlay -> node-b forwarding -> inventory 10.42.2.20Service: shop -> 10.96.0.40:80 -> service dataplane -> 10.42.2.20:8080What CNI does when a Pod starts
Container Network Interface (CNI) defines an agreement between a runtime and network plugins. For an ordinary network attachment, the runtime prepares the sandbox network namespace and calls the configured plugin chain to establish connectivity; an IP address management plugin may allocate addresses. In a common Linux veth design, a virtual Ethernet pair joins the Pod namespace to forwarding on the node. Other implementations may use different interfaces. CNI ADD establishes an attachment and DEL requests cleanup; the specification defines other operations with version-specific requirements. A CNI configuration version is not a Kubernetes or plugin release version. A plugin result is not proof that DNS, Services or an application work. A separate controller or agent may program ongoing routes, policies or Service forwarding.
From a Pod IP to a Service destination
In topology.json, shop has 10.42.1.10 on node-a and inventory has 10.42.2.20 on node-b. A direct call targets 10.42.2.20:8080; a Service call targets its illustrative virtual IP 10.96.0.40:80 and the Service dataplane selects a backend. The backend still needs a working Pod path and a listening application. kube-proxy can implement Service forwarding, or a supported alternative dataplane can do so. The following Service declares a selector and port mapping; it does not allocate the exact example ClusterIP explicitly, deploy a backend, or guarantee reachability. External traffic adds ingress or load-balancer and routing decisions; outbound traffic may be translated at an egress boundary. Pod-to-Pod addressing is distinct from external NAT behavior.
apiVersion: v1kind: Servicemetadata: name: inventory namespace: network-studyspec: selector: app: inventory ports: - name: http port: 80 targetPort: 8080Diagnose by narrowing the failing path
First confirm the destination process and its listening address in an approved fixture. Compare same-Pod, same-node and cross-node results using the same application protocol. If direct backend communication works but the Service does not, review selectors, EndpointSlices, readiness, port mapping and the Service dataplane. A failed cross-node probe may indicate routing, encapsulation, policy, MTU or a return-path issue; it does not uniquely prove a broken CNI. DNS is a separate check. Policy enforcement depends on the configured implementation, not merely the existence of a NetworkPolicy object. Do not change host routes or disable controls during diagnosis.
Practice tracing the bookstore
Read topology.json and path-cases.json. Draw the forwarding path from shop to cache, then from shop to inventory. Explain which IP and port are visible at the Service entry and backend in the simplified model. Identify where you would inspect evidence if the same-node case works but cross-node fails. Run the offline validator to check your model, not to verify live connectivity. Next: IPAM and dataplanes.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Pod networking and CNI — knowledge check
Reason about synthetic Kubernetes networking scenarios.
A companion container in the same ordinary Pod calls localhost:8080. Where does the request go?
The shop Pod directly calls inventory on a different node. Which destination is used?
What does CNI ADD describe?
The backend works directly but its Service fails. What should you inspect next?
Does creating a NetworkPolicy always enforce it?