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
Official competencies this lesson covers
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
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
| Layer | Example range | Who allocates the addresses | Who makes them reachable |
|---|---|---|---|
| Node network | 192.168.1.0/24 | You, your cloud or your DHCP server | Your real switches and routers |
| Pod network | 10.244.0.0/16 | The CNI plugin's IPAM | The CNI plugin (bridges, routes, tunnels) |
| Service network | 10.96.0.0/12 | The kube-apiserver | kube-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
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
- 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.
- The EndpointSlice controller finds the ready Pods that match the selector and writes their IPs and ports into EndpointSlices.
- 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:80goes to one of10.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
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
- The client Pod on
node01sends a packet to10.96.14.20:80. - The packet leaves the Pod and enters the kernel of
node01. Before routing, the kube-proxy rules match the destination address, protocol and port. - 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. - The packet now has a Pod address as destination, so the Pod network carries it to
node02like any other Pod to Pod packet.
Nothing along the way owns 10.96.14.20. That has practical consequences:
ip addron a node never shows a ClusterIP, andss -tlnpshows no listener for a Service or node port.pingto a ClusterIP usually fails even when the Service is healthy. The rules match a protocol and a port, and ICMP has neither. Test withcurlorncon 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
| Chain | One per | What it does |
|---|---|---|
KUBE-SERVICES | cluster (one rule per Service port) | Matches the ClusterIP, protocol and port, jumps to the Service's chain |
KUBE-SVC-… | Service port | Picks one endpoint at random |
KUBE-SEP-… | endpoint | DNAT to that Pod's IP and target port |
KUBE-NODEPORTS | cluster | Matches 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
| Type | What exists on each node |
|---|---|
ClusterIP | Rules for ClusterIP:port |
NodePort | The ClusterIP rules, plus a rule for any node address:nodePort (range 30000 to 32767) |
LoadBalancer | The 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 |
ExternalName | Nothing. DNS returns a CNAME |
Proxy modes
| Mode | Rules live in | Status |
|---|---|---|
iptables | iptables NAT chains | The default on Linux |
nftables | One nftables table named kube-proxy | Stable, faster with many Services, announced as the future default |
ipvs | The kernel's IPVS load balancer | Deprecated 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
ServiceCIDRobject and every allocated address as anIPAddressobject:kubectl get servicecidrandkubectl get ipaddresses. Adding a secondServiceCIDRis 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.1on kubeadm. The tenth,10.96.0.10, iskube-dns. - kube-proxy's own idea of the Pod range. Its
clusterCIDRsetting 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-rangeis 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 KUBEon 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/12on 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/nameas a comment, sogrepfollows 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.