Skip to content
LF Cert Trainer

Lesson 114 · Section 9: Networking

Lesson 114: Service networking: how a virtual IP is laid over the Pod network

How Service networking sits on top of the Pod network: the Service range and who owns it, how kube-proxy turns a Service into rules on every node, how to follow one Service through those rules, and a fixed order of checks when a Service does not answer. · 20 min read · 2 min video

1/8Service networking
0:00 / 2:23

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

Why a second network on top of the Pod network

The last lessons built the Pod network: every Pod has a unique address and any Pod can reach any other, on any node. That is enough to connect two Pods, and useless for connecting two applications. Pods are replaced on every rollout, crash and node drain, and each replacement gets a new address. An application of five replicas has five addresses that will all be different tomorrow.

The lessons on Services and kube-proxy in the Core Concepts section introduced the answer: a Service gives a group of Pods one stable address. This lesson looks at that from the network's side. Where does that address live? Which range does it come from? What exactly is on a node after you create a Service, and how do you follow it when something is wrong?

What it is made of

Three networks, three ownersowned bywatchowned byowned bytranslated tocarried overService network10.96.0.0/12API serverallocates the IPkube-proxymakes it workPod network10.244.0.0/16CNI pluginallocates and routesNode network192.168.1.0/24Youreal network
Three networks, three owners. Each layer has its own address range and its own owner. Service addresses are the only ones that exist on no interface at all.

Parts:

  • Service network (10.96.0.0/12)
  • API server (allocates the IP)
  • kube-proxy (makes it work)
  • Pod network (10.244.0.0/16)
  • CNI plugin (allocates and routes)
  • Node network (192.168.1.0/24)
  • You (real network)

Connections:

  • Service network to API server: owned by
  • API server to kube-proxy: watch
  • Pod network to CNI plugin: owned by
  • Node network to You: owned by
  • Service network to Pod network: translated to
  • Pod network to Node network: carried over
LayerExample rangeWho allocates the addressesWho makes them reachable
Node network192.168.1.0/24You, your cloud or your DHCP serverYour real switches and routers
Pod network10.244.0.0/16The CNI plugin's IPAMThe CNI plugin (bridges, routes, tunnels)
Service network10.96.0.0/12The kube-apiserverkube-proxy, with rules in each node's kernel

The three ranges must not overlap. A Pod address that also falls inside the Service range would be caught by the wrong rule or routed to the wrong place.

The Service range is set on the API server with --service-cluster-ip-range. If the flag is missing, the built-in default is 10.0.0.0/24. kubeadm always sets it, to 10.96.0.0/12 unless you pass --service-cidr:

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

10.96.0.0/12 covers 10.96.0.0 to 10.111.255.255. So a ClusterIP such as 10.103.132.104 is perfectly normal on a kubeadm cluster.

How it works

From a Service object to rules on every node

From kubectl expose to rules on every nodecreatecontrollerwatchwatchprogramkubectl exposeService webAPI serverpicks 10.96.14.20EndpointSliceready Pod IPskube-proxynode01kube-proxynode02Kernel rulessame on every node
From kubectl expose to rules on every node. Three independent watchers react to a new Service. Only kube-proxy touches the nodes, and it writes the same rules on all of them.

Parts:

  • kubectl expose (Service web)
  • API server (picks 10.96.14.20)
  • EndpointSlice (ready Pod IPs)
  • kube-proxy (node01)
  • kube-proxy (node02)
  • Kernel rules (same on every node)

Connections:

  • kubectl expose to API server: create
  • API server to EndpointSlice: controller
  • API server to kube-proxy: watch
  • API server to kube-proxy: watch
  • kube-proxy to Kernel rules: program
  1. You create a Service. The API server picks a free address from the Service range and saves the object. At this point the address is only a number in etcd.
  2. The EndpointSlice controller finds the ready Pods that match the selector and writes their IPs and ports into EndpointSlices.
  3. kube-proxy runs on every node as a DaemonSet Pod and watches Services and EndpointSlices. For each Service port it writes rules into its node's kernel: "a new connection to 10.96.14.20:80 goes to one of 10.244.1.9:8080, 10.244.2.4:8080".

Services are cluster-wide, so every node gets the same rules, whether or not it runs a backend Pod. A Service is therefore reachable from any Pod and from any node's own shell.

One connection, step by step

One connection, from ClusterIP to a Pod on another nodenode01to :80rewrittendelivers to node02or this onePod client10.244.1.5Rules on node01DNAT to a PodPod networkCNI pluginPod web-110.244.2.4:8080Pod web-210.244.1.9:8080
One connection, from ClusterIP to a Pod on another node. The translation happens on the client's node, before the packet leaves it. After that it is ordinary Pod to Pod traffic.

Parts:

  • Pod client (10.244.1.5), in node01
  • Rules on node01 (DNAT to a Pod), in node01
  • Pod network (CNI plugin)
  • Pod web-1 (10.244.2.4:8080)
  • Pod web-2 (10.244.1.9:8080), in node01

Connections:

  • Pod client to Rules on node01: to :80
  • Rules on node01 to Pod network: rewritten
  • Pod network to Pod web-1: delivers to node02
  • Rules on node01 to Pod web-2: or this one
  1. The client Pod on node01 sends a packet to 10.96.14.20:80.
  2. The packet leaves the Pod and enters the kernel of node01. Before routing, the kube-proxy rules match the destination address, protocol and port.
  3. A rule picks one backend and rewrites the destination: DNAT to 10.244.2.4:8080. The kernel's connection tracking remembers the choice for the rest of the connection and rewrites the replies back.
  4. The packet now has a Pod address as destination, so the Pod network carries it to node02 like any other Pod to Pod packet.

Nothing along the way owns 10.96.14.20. That has practical consequences:

  • ip addr on a node never shows a ClusterIP, and ss -tlnp shows no listener for a Service or node port.
  • ping to a ClusterIP usually fails even when the Service is healthy. The rules match a protocol and a port, and ICMP has neither. Test with curl or nc on the Service port.
  • The Pod network must work first. If Pods on two nodes cannot reach each other by Pod IP, no Service between them can work.

What the rules look like

In the default iptables mode the rules are chains in the NAT table:

iptables -t nat -S | grep default/web
-A KUBE-SERVICES -d 10.96.14.20/32 -p tcp -m comment --comment "default/web cluster IP" --dport 80 -j KUBE-SVC-LOLE4ISW44XBNF3G
-A KUBE-SVC-LOLE4ISW44XBNF3G -m comment --comment "default/web -> 10.244.1.9:8080" -m statistic --mode random --probability 0.5 -j KUBE-SEP-QKX4QX54UKWK6JLY
-A KUBE-SVC-LOLE4ISW44XBNF3G -m comment --comment "default/web -> 10.244.2.4:8080" -j KUBE-SEP-CI5ZO3FTK7KBNRMG
-A KUBE-SEP-CI5ZO3FTK7KBNRMG -p tcp -m comment --comment "default/web" -j DNAT --to-destination 10.244.2.4:8080
ChainOne perWhat it does
KUBE-SERVICEScluster (one rule per Service port)Matches the ClusterIP, protocol and port, jumps to the Service's chain
KUBE-SVC-…Service portPicks one endpoint at random
KUBE-SEP-…endpointDNAT to that Pod's IP and target port
KUBE-NODEPORTSclusterMatches node ports and jumps into the same KUBE-SVC-… chains

Every rule carries a comment with namespace/name, so grep finds a Service without knowing any chain name.

Service types, seen from the network

TypeWhat exists on each node
ClusterIPRules for ClusterIP:port
NodePortThe ClusterIP rules, plus a rule for any node address:nodePort (range 30000 to 32767)
LoadBalancerThe NodePort rules, plus an external load balancer that sends to the nodes
Headless (clusterIP: None)Nothing. No virtual IP, no rules. DNS returns the Pod IPs directly
ExternalNameNothing. DNS returns a CNAME

Proxy modes

ModeRules live inStatus
iptablesiptables NAT chainsThe default on Linux
nftablesOne nftables table named kube-proxyStable, faster with many Services, announced as the future default
ipvsThe kernel's IPVS load balancerDeprecated since Kubernetes 1.35

The mode is the mode field of the kube-proxy configuration, kept in the ConfigMap kube-proxy in kube-system. An empty value means the default. The behaviour in this lesson is the same in every mode. Only the command that shows the rules changes: iptables -t nat -S, nft list table ip kube-proxy, or ipvsadm -Ln.

Under the hood · Details worth knowing
  • The range as an object. Current clusters publish the Service range as a ServiceCIDR object and every allocated address as an IPAddress object: kubectl get servicecidr and kubectl get ipaddresses. Adding a second ServiceCIDR is the supported way to extend a range that is running full.
  • Two fixed addresses. The first address of the range is the Service kubernetes (the API server), 10.96.0.1 on kubeadm. The tenth, 10.96.0.10, is kube-dns.
  • kube-proxy's own idea of the Pod range. Its clusterCIDR setting tells it which sources are Pods. Traffic to a ClusterIP from outside that range is masqueraded.
  • Plugins that replace kube-proxy. Cilium can implement Services itself with eBPF. On such a cluster there is no kube-proxy DaemonSet and no KUBE- chains, and that is not a fault.
  • Rules outlive the process. Stopping kube-proxy does not remove rules. They just stop being updated on that node.

Using it

Example · Name the three ranges of a cluster

Task: "What are the IP ranges of the nodes, the Pods and the Services?"

Nodes. Take a node's internal IP and look up its prefix on the node:

kubectl get nodes -o wide
ip -brief addr | grep 192.168.1.10
NAME           STATUS   ROLES           AGE   VERSION   INTERNAL-IP
controlplane   Ready    control-plane   12d   v1.34.1   192.168.1.10
node01         Ready    <none>          12d   v1.34.1   192.168.1.11
eth0             UP             192.168.1.10/24

The node network is 192.168.1.0/24.

Pods. From the previous lesson:

kubectl -n kube-system get pod -l component=kube-controller-manager -o yaml | grep cluster-cidr
    - --cluster-cidr=10.244.0.0/16

Services.

kubectl -n kube-system get pod -l component=kube-apiserver -o yaml | grep service-cluster-ip-range
    - --service-cluster-ip-range=10.96.0.0/12

Reading the flags through the static Pods' objects saves an SSH hop to the control plane node.

Example · Follow a Service down to its Pods

Task: "Show how traffic to Service web is distributed on node01."

Start with the objects:

kubectl get svc web
kubectl get endpointslices -l kubernetes.io/service-name=web
NAME   TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
web    ClusterIP   10.96.14.20   <none>        80/TCP    5m
NAME        ADDRESSTYPE   PORTS   ENDPOINTS                 AGE
web-x7k2p   IPv4          8080    10.244.1.9,10.244.2.4     5m

Then find the same facts in the kernel of the node:

ssh node01
iptables -t nat -S | grep 'default/web'

The output is the listing shown under "What the rules look like": one KUBE-SERVICES rule for 10.96.14.20:80, two KUBE-SVC rules that split connections half and half, and two KUBE-SEP rules with the DNAT targets. The ClusterIP, the port, the Pod IPs and the target port all match the objects. If they did not, kube-proxy on this node would be behind.

Example · A Service that does not answer

Task: "Pods cannot reach Service web on port 80. Fix it." Work from the object towards the node, and stop at the first check that fails.

1. Endpoints.

kubectl get endpointslices -l kubernetes.io/service-name=web

No addresses means the selector matches no ready Pod: compare kubectl get svc web -o wide (the SELECTOR column) with kubectl get pods --show-labels, and check that the Pods are Ready. Here the list has two addresses, so continue.

2. The Pod itself, without the Service.

kubectl run t --rm -it --restart=Never --image=busybox:1.37 -- wget -qO- -T 2 10.244.2.4:8080

An answer proves the application and the Pod network. No answer on the Pod IP means the problem is the Pod, the targetPort, the CNI plugin or a NetworkPolicy, not Service networking.

3. kube-proxy.

kubectl -n kube-system get pods -l k8s-app=kube-proxy -o wide
NAME               READY   STATUS             RESTARTS      AGE   NODE
kube-proxy-8zq4d   1/1     Running            0             12d   controlplane
kube-proxy-tk5rn   0/1     CrashLoopBackOff   6 (40s ago)   6m    node01
kubectl -n kube-system logs kube-proxy-tk5rn
E1130 10:02:11 run.go:74] "command failed" err="failed complete: open /var/lib/kube-proxy/configuration.conf: no such file or directory"

The DaemonSet's command points at a file that does not exist. The ConfigMap is mounted with the key config.conf:

kubectl -n kube-system edit ds kube-proxy     # --config=/var/lib/kube-proxy/config.conf
kubectl -n kube-system rollout status ds kube-proxy

4. The rules. With kube-proxy running again, iptables -t nat -S | grep default/web on node01 shows the chains, and the test from step 2 against web:80 answers.

Tricks

Common mistakes

  • Looking for the ClusterIP on an interface. It is only in the kube-proxy rules.
  • Searching for the Service range on kube-proxy or the controller manager. The flag --service-cluster-ip-range is on the API server. (The controller manager has a flag of the same name, used only to keep node Pod slices out of the Service range.)
  • Debugging kube-proxy when the Service has no endpoints. Always start with the EndpointSlices.
  • Testing the Service before testing a Pod IP. If Pod to Pod traffic is broken, the fault is one layer down.
  • Expecting the same commands in every proxy mode. An empty iptables -t nat -S | grep KUBE on an nftables or Cilium cluster is normal.

Recap

  • A cluster has node, Pod and Service ranges, each with its own owner, and they must not overlap.
  • Service IPs are virtual and come from the API server's --service-cluster-ip-range (10.96.0.0/12 on kubeadm).
  • kube-proxy on every node turns Services and EndpointSlices into rules that DNAT to a ready Pod. The Pod network then delivers the packet.
  • Rules carry the Service's namespace/name as a comment, so grep follows a Service into the kernel.
  • When a Service fails, check endpoints, then a Pod IP, then kube-proxy on the client's node, then the rules.

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.

Practise: try it on a real cluster

2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Follow a Service from its object to the node: find the range ClusterIPs come from, give a Service a fixed address in it, and find the rule on the node that makes the address work.

    Investigate · Level 2 · standard · target 18 min

  • Section capstone. Repair a Service and a Pod's name resolution, then move the shop from an Ingress to a Gateway with routes that keep its paths, strip a prefix and redirect an old host name.

    Build · Level 3 · challenge · target 35 min

Discussion

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