Quick Summary
- Every pod in Kubernetes gets its own IP address and can communicate with any other pod directly
- Services provide stable endpoints (ClusterIP) that load-balance traffic to a set of pods
- NodePort and LoadBalancer services expose pods to external traffic in different ways
The Kubernetes Networking Model
Kubernetes networking follows a deceptively simple set of rules. First, every pod gets its own unique IP address -- no manual assignment, no port conflicts. Second, any pod can communicate with any other pod in the cluster using that IP address directly, without NAT. Third, agents on a node (like kubelet) can communicate with all pods on that node. These three rules create a flat network where every pod is a first-class citizen.
This flat network model is implemented by Container Network Interface (CNI) plugins -- software that creates the actual network plumbing. Popular CNI plugins include Calico (which uses BGP routing for high performance), Flannel (which uses simple VXLAN overlays), Cilium (which uses eBPF for advanced security and observability), and Weave Net (which creates a mesh overlay). Each plugin implements the same model differently, with tradeoffs in performance, features, and complexity.
But pod IPs are ephemeral. When a pod restarts, it gets a new IP address. If you have three replicas of your web server and one crashes, the replacement pod will have a different IP. This is where Services come in -- they provide a stable virtual IP (ClusterIP) that automatically routes traffic to whatever pods are currently running, regardless of their individual IPs.
Interactive: Service Type Comparison
Click each service type below to see how the traffic path changes for external and internal access patterns.
How kube-proxy Routes Traffic
Service Discovery
When you create a Kubernetes Service, the control plane assigns it a stable virtual IP (ClusterIP) and a DNS name (like my-service.default.svc.cluster.local). Every pod in the cluster can reach the service using either the IP or the DNS name. CoreDNS, the cluster DNS server, automatically creates records for every service. Applications just call the service by name -- no hardcoded IPs.
iptables / IPVS Rules
kube-proxy runs on every node and watches for Service and Endpoint changes. In iptables mode (the default), it programs NAT rules that intercept traffic to the ClusterIP and redirect it to one of the backend pod IPs. In IPVS mode, it uses the Linux kernel's IP Virtual Server for more efficient load balancing with less overhead at scale. Either way, the mechanism is transparent to applications -- they send traffic to the service IP, and the kernel handles the rest.
Endpoints and EndpointSlices
The Endpoints (or EndpointSlices in newer versions) resource tracks which pod IPs belong to which service. When a pod passes its readiness probe, its IP is added to the service's endpoint list. When a pod fails or is terminated, its IP is removed. This automatic registration and deregistration is what makes services resilient -- they always route to healthy pods only, with no manual intervention required.
Pod-to-Pod Communication
In Kubernetes, pods communicate directly using IP addresses, without NAT. If Pod A at 10.244.1.5 wants to talk to Pod B at 10.244.2.8, the packet goes directly from A to B. This works even when the pods are on different nodes. The CNI plugin is responsible for making this work -- it sets up routes, tunnel overlays, or BGP peering so that every node knows how to reach every pod subnet.
This flat networking model is fundamentally different from Docker's default bridge networking. In Docker, containers on different hosts cannot communicate without port mapping or overlay networks. Kubernetes mandates that all pods can reach each other, and delegates the implementation to the CNI plugin. This simplifies application design -- services can assume direct reachability to any pod, just like processes on a traditional server can assume reachability to any other process.
Network Policies
By default, Kubernetes allows all pod-to-pod traffic. This is convenient for development but dangerous in production. Network Policies let you define firewall rules at the pod level. You can specify that only pods with a specific label (like "role: frontend") can connect to pods with another label (like "role: api"), and only on specific ports. Network Policies are implemented by the CNI plugin -- Calico and Cilium support them fully, while Flannel does not. Without a CNI plugin that enforces Network Policies, the policy resources are ignored by the cluster.
Ingress: HTTP Routing from Outside
Ingress Controller
Ingress resources define HTTP routing rules (host-based, path-based) for external traffic. An Ingress controller (NGINX, Traefik, or HAProxy) implements these rules by configuring a reverse proxy that routes to the appropriate services.
TLS Termination
Ingress controllers handle TLS certificates, terminating HTTPS at the edge and forwarding plain HTTP to backend pods. cert-manager automates certificate provisioning from Let's Encrypt, keeping your services encrypted without manual certificate management.
Gateway API
The newer Gateway API is replacing Ingress with a more expressive, role-oriented model. It separates infrastructure concerns (GatewayClass, Gateway) from application routing (HTTPRoute), giving platform teams and developers independent control over their respective domains.
Service Mesh
For complex microservice architectures, a service mesh like Istio, Linkerd, or Consul Connect adds a sidecar proxy (typically Envoy) to every pod. This sidecar intercepts all traffic and provides mutual TLS encryption, fine-grained traffic management (canary deployments, circuit breaking, retries), and detailed observability (request latency, error rates, distributed tracing) -- all without modifying application code. The mesh control plane manages configuration across all sidecars centrally.
Service meshes add complexity and resource overhead (each sidecar consumes CPU and memory), so they are typically justified only for large deployments with many services. For smaller clusters, Kubernetes' built-in Service and Network Policy mechanisms are usually sufficient. Cilium's eBPF-based approach offers many mesh-like features without sidecars, representing a newer approach that reduces overhead.
Frequently asked questions about Kubernetes networking
What is the Kubernetes networking model?
Kubernetes requires that every pod gets its own IP address and that any pod can talk to any other pod without NAT. The cluster network is implemented by a CNI plugin (Calico, Cilium, Flannel, etc.) that wires up routes, tunnels, or overlays between nodes to make this flat model work.
What is a Service in Kubernetes?
A Service is a stable virtual IP and DNS name that load-balances traffic to a set of pods selected by labels. Pods come and go, but the Service IP stays the same — clients always talk to the Service, and kube-proxy or eBPF rules redirect traffic to a healthy backend pod.
What is the difference between ClusterIP, NodePort, and LoadBalancer?
ClusterIP is reachable only inside the cluster. NodePort exposes the Service on a port on every node, so external clients can hit any node IP. LoadBalancer asks the cloud provider for a real external load balancer that routes inbound traffic to the NodePorts behind the scenes.
What is a CNI plugin?
CNI (Container Network Interface) is the standard that lets Kubernetes call out to a pluggable network implementation. The CNI plugin is responsible for assigning pod IPs, setting up veth pairs, and routing or encapsulating traffic between pods on different nodes.
How do NetworkPolicies work?
A NetworkPolicy is a Kubernetes object that defines which pods can talk to which other pods on which ports. The CNI plugin enforces these policies, usually by programming iptables or eBPF rules on each node. Without any NetworkPolicy, all pod-to-pod traffic is allowed by default.
Try container networking
You just learned the Kubernetes networking model. Now build the pieces underneath: subnets joined by a router, and a load balancer that forwards a virtual IP to backend servers. Trace a connection to see the address rewrite in the Packet Inspector, then press Go Live to run it on real namespaces, bridges and iptables.
Launch the container networking lab →