Networking is the part of Kubernetes that confuses people the longest. A Pod starts, gets an IP address, and somehow other Pods can reach it. A Service appears with a stable name. Traffic from the internet finds its way to the right container. Each of these steps is handled by a different piece, and some of those pieces are not part of Kubernetes at all.
This guide walks through the whole path in plain English: the network model, CNI plugins, Services and kube-proxy, cluster DNS, Ingress, Gateway API and NetworkPolicy. Once you know which component owns which job, debugging and design decisions get much easier.
The Kubernetes network model in four rules
The official networking overview describes a small set of rules that every conformant cluster follows:
- Every Pod gets its own cluster-wide IP address. Containers inside the same Pod share one network namespace, so they talk to each other over localhost.
- Pods reach other Pods directly. All Pods can communicate with all other Pods, on the same node or a different one, without proxies or address translation (NAT), unless you segment the network on purpose.
- Node agents can reach local Pods. System daemons and the kubelet on a node can talk to every Pod on that node.
- Services give stable addresses. Pods come and go, so the Service API provides a long-lived IP address or hostname in front of a changing set of backend Pods.
The important detail is that Kubernetes only implements a few of these parts itself. For the rest, Kubernetes defines the API and expects an external component to do the work. That split explains why two clusters can behave quite differently even though they run the same Kubernetes version.
CNI: who builds the Pod network
The Pod network is provided by a pod network implementation. On Linux, most container runtimes talk to that implementation through the Container Network Interface (CNI), which is why these implementations are usually called CNI plugins.
CNI is a CNCF project. It is a specification plus libraries for writing plugins that configure network interfaces in Linux and Windows containers. Its scope is deliberately narrow: connect a container to the network when it starts, and clean up the allocated resources when it is deleted. Because the spec is small, many networking projects implement it.
In practice the CNI plugin you choose often does more than connectivity. The Kubernetes docs note that some pod network implementations replace kube-proxy with their own, more tightly integrated service proxy, and that NetworkPolicy is generally enforced by the pod network implementation too. So the choice of CNI decides how Services are load balanced, whether NetworkPolicy works, and what observability you get. If you run Cilium, our guide to Cilium network policies with L3, L4 and L7 filtering shows how far a modern CNI can go.
Services, EndpointSlices and kube-proxy
Pods are disposable, so you should never hard-code a Pod IP. A Service selects Pods by label and gives them one stable address. Kubernetes keeps EndpointSlice objects up to date with the Pods that currently back each Service. A service proxy watches Services and EndpointSlices and programs the data plane so that traffic sent to the Service reaches a healthy backend.
The default service proxy is kube-proxy. According to the Virtual IPs and Service Proxies reference, on Linux it can run in iptables, ipvs or nftables mode. The ipvs mode is deprecated, and the docs say a future Kubernetes release will change the default from iptables to nftables, so it is worth setting the mode explicitly in production.
Every Service has a type that controls how it is exposed:
- ClusterIP (the default): a cluster-internal IP, reachable only from inside the cluster.
- NodePort: opens the same static port on every node, by default from the 30000-32767 range, and forwards it to the Service. A cluster IP is created as well.
- LoadBalancer: exposes the Service through an external load balancer. Kubernetes does not ship one, so it comes from your cloud provider or an add-on you install.
- ExternalName: no proxying at all. Cluster DNS returns a CNAME record that points to an external hostname.
There is also the headless Service, created by setting .spec.clusterIP to None. It skips the virtual IP and load balancing, which is useful for stateful workloads or clients that want to pick a specific Pod.
Here is the basic Service example from the Kubernetes documentation. It sends traffic arriving on port 80 to port 9376 on any Pod labeled app.kubernetes.io/name: MyApp:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app.kubernetes.io/name: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
Cluster DNS: how names resolve
Applications rarely use Service IPs directly. Instead they use names. Per the DNS for Services and Pods page, a normal Service gets A and/or AAAA records of the form my-svc.my-namespace.svc.cluster-domain.example, which resolve to the Service cluster IP. For a headless Service, the same name resolves to the set of IPs of all selected Pods instead.
This is why a Pod in the same namespace can usually reach a backend just by calling http://my-service. When that fails, DNS is one of the first things to check, along with whether the Service actually has endpoints.
Getting traffic in: Ingress and Gateway API
ClusterIP Services are internal. To accept traffic from outside the cluster you have three main options: a Service of type LoadBalancer (simple, but with no HTTP routing rules of its own), Ingress, or Gateway API.
Ingress has been stable since Kubernetes v1.19. It routes HTTP and HTTPS traffic using hostnames and paths. An Ingress object does nothing by itself: you must run an Ingress controller to satisfy it. The Ingress documentation now states that the Kubernetes project recommends Gateway instead of Ingress and that the Ingress API is frozen. It stays generally available and there are no plans to remove it, but it will not get new features. Many advanced behaviors in Ingress were only possible through controller-specific annotations, which made configs hard to move between controllers.
Gateway API is the successor. It is an official Kubernetes project run by SIG Network, focused on L4 and L7 routing. Its resources are Custom Resources, so you install the Gateway API CRDs (or follow your implementation’s install steps) and then pick an implementation. The Kubernetes Gateway API page lists four stable kinds:
- GatewayClass: a type of gateway, managed by the controller that implements it.
- Gateway: an instance of traffic handling infrastructure, such as a cloud load balancer, with listeners for ports, protocols and hostnames.
- HTTPRoute: HTTP rules that map traffic from a Gateway listener to backends, usually Services.
- GRPCRoute: the same idea for gRPC traffic.
The design is role-oriented. An infrastructure provider manages GatewayClasses, a cluster operator manages Gateways and policies, and application developers attach their own Routes. Header matching and traffic weighting are part of the API itself rather than annotations. Gateway API also covers service mesh (east-west) traffic through the GAMMA initiative, where routes attach directly to Services.
Gateway API does not include an Ingress kind, so moving over is a one-time conversion. Our walkthrough on how to migrate to Kubernetes Gateway API covers that process step by step.
Hands-on: inspect the network path yourself
Prerequisites: a running cluster, kubectl configured for it, and a Deployment called my-nginx with Pods labeled run: my-nginx, as created in the official Connecting Applications with Services tutorial. The commands below come from that tutorial.
See the Pod IPs, create a Service for the Deployment, and look at its EndpointSlices and the cluster DNS Service:
kubectl get pods -l run=my-nginx -o custom-columns=POD_IP:.status.podIPs
kubectl expose deployment/my-nginx
kubectl get svc my-nginx
kubectl describe svc my-nginx
kubectl get endpointslices -l kubernetes.io/service-name=my-nginx
kubectl get services kube-dns --namespace=kube-system
To try Gateway API, install the standard channel CRDs. This is the command from the Gateway API getting started guide at the time of writing; check that page for the latest release:
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.1/standard-install.yaml
The CRDs alone do not route traffic. You also need an implementation that provides a GatewayClass. With one installed, a Gateway and an HTTPRoute look like this (examples from the Kubernetes docs; replace example-class with your GatewayClass):
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: example-gateway
namespace: example-namespace
spec:
gatewayClassName: example-class
listeners:
- name: http
protocol: HTTP
port: 80
hostname: "www.example.com"
allowedRoutes:
namespaces:
from: Same
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: example-httproute
spec:
parentRefs:
- name: example-gateway
hostnames:
- "www.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /login
backendRefs:
- name: example-svc
port: 8080
If traffic still does not arrive, our guide to fixing Kubernetes network issues with kubectl and tcpdump shows how to follow packets through the cluster.
NetworkPolicy: controlling who can talk to whom
By default, the network model lets every Pod reach every other Pod. NetworkPolicy is the built-in API for restricting that at the IP and port level (OSI layer 3 or 4). There is one catch: network policies are implemented by the network plugin. If your CNI does not support NetworkPolicy, you can still create the objects, but they have no effect.
A common first step is a default deny policy for incoming traffic in a namespace, then explicit allow rules for the flows you need. This example from the docs selects every Pod in the namespace and allows no ingress:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes:
- Ingress
Key takeaways
- Every Pod gets its own IP, and Pods talk to each other directly without NAT. A CNI plugin builds that Pod network.
- Your CNI choice matters beyond connectivity: it may replace kube-proxy and it decides whether NetworkPolicy is enforced.
- Services give Pods a stable IP and DNS name. EndpointSlices track the backends, and a service proxy such as kube-proxy routes the traffic.
- kube-proxy supports iptables, ipvs and nftables on Linux. ipvs is deprecated and the default is expected to move to nftables, so set the mode explicitly.
- Ingress is stable but frozen. The Kubernetes project recommends Gateway API, which is role-oriented, more expressive and also covers service mesh traffic.
- Gateway API resources are CRDs. You need both the CRDs and an implementation that provides a GatewayClass.
- Start namespaces with a default deny NetworkPolicy and open only the flows you need, after confirming your CNI enforces policies.
Sources
Kubernetes documentation: Services, Load Balancing, and Networking, Service, Virtual IPs and Service Proxies, DNS for Services and Pods, Ingress, Gateway API, Network Policies and Connecting Applications with Services. Gateway API project: Introduction and Getting started. CNI project: cni.dev.
