Skip to content
LF Cert Trainer

Lesson 102 · Section 9: Networking

Lesson 102: Networking introduction: how a cluster's network fits together

The map for the Networking section: the four connection problems Kubernetes solves, the three address ranges every cluster has, which component builds each layer, and the order in which to check them when something cannot connect. · 12 min read · 3 min video

1/8Networking introduction
0:00 / 2:55

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

What this section is about

Up to now you have used the cluster's network without looking at it. You created a Service and a Pod reached it by name. You ran kubectl logs and the API server reached a kubelet on another machine. All of that worked because several separate pieces were already in place.

This section opens them one at a time. It is a long section, because networking is where three different worlds meet: plain Linux networking (interfaces, routes, DNS), the container world (network namespaces, CNI), and Kubernetes objects (Services, Ingress, Gateway, NetworkPolicy). When people say Kubernetes networking is hard, they usually mean that a problem can sit in any of the three.

This lesson is the map. It teaches no new command in depth. It tells you which problems exist, which component solves each, and in which order the following lessons take them.

Why it matters for the exam

"Servicing and Networking" is 20 % of the CKA curriculum, and "Troubleshooting" (30 %) includes "Troubleshoot services and networking". On top of that, installing a cluster with kubeadm is not finished until a network plugin runs: nodes stay NotReady and CoreDNS stays Pending without one. So a good part of your score depends on knowing where to look when two things cannot talk.

The four connection problems

Every network question in Kubernetes is one of these four.

ProblemHow Kubernetes solves itWhere you learn it
Container to container, inside one PodThe containers of a Pod share one network namespace, so they talk over localhost and share one IP address and one set of portsNetwork Namespaces
Pod to Pod, anywhere in the clusterEvery Pod gets its own IP address from the Pod range, and a CNI plugin connects all of themPod Networking, CNI in Kubernetes
Pod to ServiceA Service has a stable virtual IP address. kube-proxy programs every node to send traffic for it to a healthy Pod, and CoreDNS gives it a nameService Networking, DNS in Kubernetes
Outside to ServiceNodePort and LoadBalancer Services open a way in. An Ingress or a Gateway routes HTTP by host name and pathIngress, Gateway API

The Kubernetes network model

Kubernetes does not ship a network. It states a few rules that any network must satisfy, and leaves the building to a plugin. The rules are short:

  1. Every Pod has its own IP address, unique in the cluster.
  2. Every Pod can reach every other Pod on that address, on the same node or on another, without NAT (network address translation). The address a Pod sees on an incoming packet is the real address of the sender.
  3. Agents on a node (the kubelet, system daemons) can reach all Pods on that node.
The Kubernetes network modelNode ANode Bno NATno NATsame nodeprobes, logsPod A10.244.1.2Pod B10.244.1.3Pod networkbuilt by a CNI pluginPod C10.244.2.2kubeletreaches local Pods
The Kubernetes network model. Every Pod has its own IP address. Any Pod can reach any other Pod on that address, on the same node or on another one, and nothing rewrites the addresses on the way.

Parts:

  • Pod A (10.244.1.2), in Node A
  • Pod B (10.244.1.3), in Node A
  • Pod network (built by a CNI plugin)
  • Pod C (10.244.2.2), in Node B
  • kubelet (reaches local Pods), in Node B

Connections:

  • Pod A to Pod network: no NAT
  • Pod network to Pod C: no NAT
  • Pod A and Pod B: same node
  • kubelet to Pod C: probes, logs

The second rule is the important one. It means a Pod behaves like a small machine on one big flat network. An application does not need to know which node it runs on, and you never have to map container ports to host ports to make two Pods talk.

Under the hood · Why not do it the Docker way?

Docker on a single host gives each container a private address behind the host and reaches the outside through NAT. To receive traffic, a container needs a port published on the host (-p 8080:80). That works for one machine. With hundreds of containers on many machines it becomes a bookkeeping problem: every published port must be unique per host, and every application must be told on which host and port its neighbours live.

Kubernetes chose the opposite rule: one IP address per Pod, reachable from everywhere in the cluster. Ports never clash between Pods, and a Pod can move to another node without anyone needing a new port number. The price is that somebody has to build a network where those addresses really are reachable across nodes. That somebody is the CNI plugin. The lessons Docker Networking and CNI compare the two approaches in detail.

Who builds each layer

Who builds each layerused bybelowenforced by pluginsends to Servicesnames to Service IPsLinux kernelinterfaces, routesCNI pluginPod IPs, Pod routeskube-proxyService IPsNetworkPolicywho may talkIngress, GatewayHTTP from outsideCoreDNSService names
Who builds each layer. Each layer stands on the one before it. Linux provides the tools, the CNI plugin gives Pods addresses, kube-proxy makes Service addresses work, CoreDNS gives Services names, and an Ingress or Gateway lets traffic in from outside.

Parts:

  • Linux kernel (interfaces, routes)
  • CNI plugin (Pod IPs, Pod routes)
  • kube-proxy (Service IPs)
  • NetworkPolicy (who may talk)
  • Ingress, Gateway (HTTP from outside)
  • CoreDNS (Service names)

Connections:

  • Linux kernel to CNI plugin: used by
  • CNI plugin to kube-proxy: below
  • CNI plugin to NetworkPolicy: enforced by plugin
  • Ingress, Gateway to kube-proxy: sends to Services
  • CoreDNS to kube-proxy: names to Service IPs
LayerOwnerWhat it doesWhere it runs
Interfaces, routes, namespacesThe Linux kernelThe raw tools everything else usesEvery node
Pod networkA CNI plugin (Flannel, Calico, Cilium, and others)Creates each Pod's network interface, gives it an IP address, and makes Pod addresses reachable across nodesA DaemonSet on every node, plus files in /etc/cni/net.d and /opt/cni/bin
Service addresseskube-proxyWatches Services and their endpoints and writes iptables, IPVS or nftables rules that redirect a Service IP to a Pod IPA DaemonSet on every node
NamesCoreDNSAnswers DNS queries such as web.shop.svc.cluster.local with the Service's IP addressA Deployment in kube-system, behind the Service kube-dns
HTTP entryAn Ingress controller or Gateway controllerAccepts outside HTTP traffic and routes it to Services by host and pathPods you install yourself
Access rulesNetworkPolicy, enforced by the CNI pluginLimits which Pods may talk to whichRules on every node

Two things in this table surprise many people:

  • A Service IP address does not exist on any interface. It is a virtual address that only appears in kube-proxy's rules. You cannot ping a ClusterIP on many clusters, and that is normal.
  • Kubernetes itself runs none of this except kube-proxy and CoreDNS. The Pod network and the Ingress or Gateway controller are add-ons you choose and install.

Three address ranges

A cluster uses three separate ranges of IP addresses. They must not overlap with each other.

RangeWho gets an addressTypical valueWhere it is set
Node networkEach node's network interface192.168.56.0/24Your infrastructure, outside Kubernetes
Pod network (cluster CIDR)Each Pod10.244.0.0/16kubeadm init --pod-network-cidr, and the CNI plugin's configuration
Service networkEach Service (ClusterIP)10.96.0.0/12--service-cluster-ip-range on the kube-apiserver

With most plugins, each node receives its own slice of the Pod range (10.244.0.0/24 for the first node, 10.244.1.0/24 for the second). That is why you can often tell from a Pod's IP address which node it runs on.

One request through every layer

One request, every layerHTTProutesweb?web:80kube-proxy rulesOutside clientshop.example.comIngress, Gatewayroutes by host, pathService web10.96.14.20:80CoreDNS10.96.0.10Pod cart10.244.1.7Pod web10.244.2.5:8080
One request, every layer. A client outside the cluster reaches a Pod through an Ingress or Gateway and a Service. A Pod inside the cluster first asks CoreDNS for the Service's address, then uses the same Service.

Parts:

  • Outside client (shop.example.com)
  • Ingress, Gateway (routes by host, path)
  • Service web (10.96.14.20:80)
  • CoreDNS (10.96.0.10)
  • Pod cart (10.244.1.7)
  • Pod web (10.244.2.5:8080)

Connections:

  • Outside client to Ingress, Gateway: HTTP
  • Ingress, Gateway to Service web: routes
  • Pod cart to CoreDNS: web?
  • Pod cart to Service web: web:80
  • Service web to Pod web: kube-proxy rules

Take a Pod cart that calls http://web:

  1. The application asks for the name web. The Pod's /etc/resolv.conf points at CoreDNS, which answers with the ClusterIP of the Service web, here 10.96.14.20.
  2. The Pod sends the request to 10.96.14.20:80.
  3. On the Pod's own node, the rules written by kube-proxy replace the destination with one of the Service's endpoints, here 10.244.2.5:8080.
  4. The Pod network carries the packet to the node where that Pod runs, and into the Pod.

A client outside the cluster has one extra step at the start: it reaches an Ingress controller or a Gateway (or a NodePort), which forwards to the same Service.

Each step depends on the one below it. If the Pod network is broken, nothing above it works, including DNS, because CoreDNS is itself a Pod.

The road ahead

The section starts on plain Linux, moves to containers, and only then returns to Kubernetes.

LessonsTopicQuestion they answer
Switching, Routing and GatewaysLinux basicsHow does a machine decide where to send a packet?
DNS, CoreDNSLinux basicsHow does a name become an address, and what does a DNS server do?
Network Namespaces, Docker Networking, CNIContainersHow does a container get its own network, and who sets it up?
Cluster Networking, Explore EnvironmentNodesWhich ports and interfaces does a cluster need?
Pod Networking, CNI in Kubernetes, IPAMPod layerHow do Pods get addresses and reach each other across nodes?
Service NetworkingService layerWhat does kube-proxy really write on a node?
DNS in Kubernetes, CoreDNS in Kubernetes, Explore DNSNamesWhich names exist, and how is CoreDNS configured in a cluster?
Ingress, Annotations and rewrite-target, Ingress NetworkingHTTP entryHow does outside HTTP traffic reach a Service?
Gateway API, Practical Guide to Gateway APIHTTP entryWhat replaces Ingress, and how do you use it?

If you already know Linux networking well, the first lessons will be quick. Do not skip them completely: the commands they use (ip addr, ip route, nslookup) are the same ones you will type on a broken node.

Looking at a real cluster

Example · Find the three address ranges

Start with the nodes. The INTERNAL-IP column is the node network:

kubectl get nodes -o wide
NAME           STATUS   ROLES           AGE   VERSION   INTERNAL-IP     OS-IMAGE             CONTAINER-RUNTIME
controlplane   Ready    control-plane   12d   v1.34.2   192.168.56.10   Ubuntu 24.04.1 LTS   containerd://1.7.27
node01         Ready    <none>          12d   v1.34.2   192.168.56.11   Ubuntu 24.04.1 LTS   containerd://1.7.27

The Pod range of the whole cluster is a flag of the controller manager, and each node's slice is in the Node object:

grep cluster-cidr /etc/kubernetes/manifests/kube-controller-manager.yaml
kubectl get nodes -o custom-columns=NAME:.metadata.name,PODS:.spec.podCIDR
    - --cluster-cidr=10.244.0.0/16
NAME           PODS
controlplane   10.244.0.0/24
node01         10.244.1.0/24

The Service range is a flag of the API server:

grep service-cluster-ip-range /etc/kubernetes/manifests/kube-apiserver.yaml
    - --service-cluster-ip-range=10.96.0.0/12

Some plugins manage Pod addresses themselves and ignore spec.podCIDR. In that case, read the plugin's own configuration, or simply look at the addresses in kubectl get pods -A -o wide.

Example · Find out which network plugin a cluster uses

A task may say "the cluster uses the installed CNI plugin" without naming it. Three places tell you:

ls /etc/cni/net.d/
10-flannel.conflist
kubectl get pods -A -o wide | grep -Ei 'flannel|calico|cilium|weave|canal'
kube-flannel   kube-flannel-ds-7xk2p   1/1   Running   0   12d   192.168.56.10   controlplane
kube-flannel   kube-flannel-ds-m4qcz   1/1   Running   0   12d   192.168.56.11   node01
ls /opt/cni/bin/
bridge  flannel  host-local  loopback  portmap  ...

The file in /etc/cni/net.d is the configuration the container runtime reads, the DaemonSet is the plugin's agent, and /opt/cni/bin holds the programs that do the work. The lesson CNI in Kubernetes explains each.

Example · See the network add-ons Kubernetes runs itself

kubectl -n kube-system get deploy,ds,svc
NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coredns   2/2     2            2           12d

NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
daemonset.apps/kube-proxy   2         2         2       2            2           kubernetes.io/os=linux   12d

NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
service/kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   12d

CoreDNS is a Deployment, kube-proxy is a DaemonSet (one Pod per node), and the DNS Service is still called kube-dns, the name of the server CoreDNS replaced.

Example · Walk a failing connection from the bottom up

A Pod cart cannot reach http://web in the namespace shop. Check one layer at a time and stop at the first that fails.

# 1. Do the target Pods run, and do they have addresses?
kubectl -n shop get pods -o wide

# 2. Does a Pod answer on its own address? (Pod network)
kubectl -n shop exec cart -- wget -qO- -T 2 http://10.244.2.5:8080

# 3. Does the Service have endpoints? (selector and ports)
kubectl -n shop get endpointslices -l kubernetes.io/service-name=web

# 4. Does the Service address answer? (kube-proxy)
kubectl -n shop exec cart -- wget -qO- -T 2 http://10.96.14.20

# 5. Does the name resolve? (CoreDNS)
kubectl -n shop exec cart -- nslookup web

If step 2 works and step 3 shows no endpoints, the problem is a label selector or a readiness probe, not the network. If steps 2 to 4 work and step 5 fails, look at CoreDNS. Later lessons go deep on each step. The order is what to remember today.

Tricks

Common mistakes

  • Looking at DNS first. A name that does not resolve is often a symptom: if the Pod network is down, CoreDNS is unreachable too. Test with IP addresses before names.
  • Trying to ping a Service. A ClusterIP is a set of rules for specific ports, not an interface. On many clusters it does not answer ping at all. Test the real port with wget, curl or nc.
  • Expecting Kubernetes to bring its own Pod network. It does not. Without a CNI plugin, Pods on different nodes cannot reach each other and nodes do not even become Ready.
  • Overlapping ranges. A Pod range that overlaps the node network or the Service range produces traffic that goes to the wrong place and is very hard to diagnose. Check the three ranges when you install a cluster.
  • Assuming NetworkPolicy always works. Policies are enforced by the CNI plugin. A plugin without policy support accepts the objects and silently ignores them.
  • Mixing up the port numbers. A Service's port, its targetPort and a container's port are three different fields. A Service with a wrong targetPort has endpoints and still refuses connections.

Recap

  • Kubernetes solves four problems: container to container, Pod to Pod, Pod to Service, and outside to Service.
  • The network model: one IP address per Pod, and every Pod reaches every other Pod without NAT.
  • Layers and owners: Linux, then the CNI plugin (Pod network), kube-proxy (Service IPs), CoreDNS (names), and an Ingress or Gateway (HTTP from outside).
  • Three ranges that must not overlap: nodes, Pods (--cluster-cidr), Services (--service-cluster-ip-range).
  • Troubleshoot from the bottom up: Pod and its IP, Pod address, Service endpoints, Service address, name.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.