The Kubernetes network model is composed of several interacting components that facilitate communication between pods, services, and external clients:
- Pod Networking: Every Pod receives a unique cluster-wide IP address. All containers within a single Pod share the same network namespace, allowing them to communicate via
localhost. - Pod-to-Pod Communication: The pod network (cluster network) ensures all pods can communicate with each other directly without NAT or proxies, regardless of whether they reside on the same node or different nodes. (Note: On Windows, this does not apply to host-network pods).
- Service API: Provides stable, long-lived IP addresses or hostnames for a set of backend pods. Kubernetes manages
EndpointSlice objects to track the pods backing a Service, and a service proxy (like kube-proxy) routes traffic to these backends. - External Access (Gateway/Ingress): The
Gateway API (or Ingress) makes Services accessible to clients outside the cluster. Alternatively, a Service can use type: LoadBalancer to leverage cloud provider integrations for ingress. - NetworkPolicy: A built-in API used to control traffic flow between pods or between pods and external entities at the IP or port level (OSI layers 3 or 4).
Implementation Note: While Kubernetes defines these APIs, the actual implementation of the pod network, CNI plugins, service proxying, and NetworkPolicy enforcement is often provided by external components or container runtimes.