Skip to content
LF Cert Trainer

Lesson 109 · Section 9: Networking

Lesson 109: Cluster Networking: what the nodes need

The network a Kubernetes cluster stands on: what every node must have, which ports each component listens on and who connects to them, and the three address ranges (nodes, Pods, Services) that must never overlap. · 14 min read · 4 min video

1/9Cluster Networking
0:00 / 3:34

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

What this lesson is about

The last lessons were about one machine: namespaces, bridges, Docker, a CNI plugin. A cluster is many machines, and before any Pod can be connected, the machines themselves must be able to talk to each other in specific ways. The API server must reach every kubelet, every kubelet must reach the API server, and etcd members must reach each other.

This lesson is about that foundation:

  • What each node needs before you install Kubernetes on it.
  • Which ports the components listen on, and who connects to them.
  • The three address ranges of a cluster, and where each is configured.
  • The four separate networking problems that the rest of this section solves one by one.

What every node needs

A node can be a physical server, a virtual machine or a cloud instance. Whatever it is, it needs:

RequirementWhyHow to check
At least one network interface with an IP address that all other nodes can reachComponents connect to each other by node addressip -br addr, ping between nodes
A unique host nameThe node registers under this namehostname
A unique MAC addressCloned virtual machines may share one, which confuses the networkip link
A unique product_uuidKubernetes uses it to tell nodes apartsudo cat /sys/class/dmi/id/product_uuid
IPv4 forwarding enabledA node routes packets between Pods and other nodessysctl net.ipv4.ip_forward
The required ports openSee the next partss -tlnp, nc -zv

IP forwarding is off by default on most Linux distributions. The documented way to turn it on so that it survives a reboot:

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

The ports

Each component listens on a well-known TCP port. These are the defaults from the Kubernetes documentation page "Ports and Protocols".

Control plane node

PortComponentWho connects
6443kube-apiserverEveryone: kubectl, kubelets, kube-proxy, scheduler, controller manager, Pods
2379-2380etcd2379: the API server (clients). 2380: other etcd members (peers)
10250kubeletThe API server (logs, exec, port-forward), Metrics Server
10259kube-schedulerItself and monitoring (health and metrics)
10257kube-controller-managerItself and monitoring (health and metrics)

Worker node

PortComponentWho connects
10250kubeletThe API server, Metrics Server
10256kube-proxyLoad balancers (health check)
30000-32767NodePort Services (TCP and UDP)Clients outside the cluster
Who listens where, and who connectsEvery nodeControl plane node6443 and 102506443to :237964436443kubelet:10250kube-proxy:10256 healthNodePort Services30000-32767kube-apiserver:6443etcd:2379 and :2380kube-scheduler:10259controller-manager:10257
Who listens where, and who connects. Everything talks to the API server on 6443. The API server calls back to each kubelet on 10250 and is the only client of etcd on 2379.

Parts:

  • kubelet (:10250), in Every node
  • kube-proxy (:10256 health), in Every node
  • NodePort Services (30000-32767), in Every node
  • kube-apiserver (:6443), in Control plane node
  • etcd (:2379 and :2380), in Control plane node
  • kube-scheduler (:10259), in Control plane node
  • controller-manager (:10257), in Control plane node

Connections:

  • kubelet and kube-apiserver: 6443 and 10250
  • kube-proxy to kube-apiserver: 6443
  • kube-apiserver to etcd: to :2379
  • kube-scheduler to kube-apiserver: 6443
  • controller-manager to kube-apiserver: 6443

Three things in this picture are worth understanding, not only memorizing.

Almost every connection goes to the API server. The scheduler, the controller manager, the kubelets and kube-proxy are all clients of port 6443. They do not talk to each other. If a worker cannot reach 6443 on the control plane, its kubelet cannot report, and the node becomes NotReady.

The API server calls back. kubectl logs, kubectl exec and kubectl port-forward make the API server open a connection to port 10250 of the node that runs the Pod. So the firewall must allow the control plane to reach 10250 on every node. A cluster where Pods run fine but kubectl logs times out usually has this port blocked.

etcd has two ports. 2379 is for clients, and the only client is the API server. 2380 is for etcd members talking to each other. It only matters when there are several control plane nodes, and then it must be open between them.

All of these are defaults and can be changed with flags. A common change is serving the API on 443, or placing a load balancer on 443 in front of several API servers on 6443.

Under the hood · Ports you will also meet: local ports and CNI plugins

ss on a node shows more than the documented list.

PortOwnerNotes
10248kubelethealthz, on 127.0.0.1 only
10249kube-proxyMetrics, on 127.0.0.1 only
2381etcdMetrics and health, on 127.0.0.1 only in kubeadm clusters
53, 9153CoreDNSInside its Pods, reached through the kube-dns Service

The network plugin needs ports between nodes as well, and they depend on the plugin and its mode:

PluginTraffic between nodes
Flannel (VXLAN)UDP 8472
CalicoTCP 179 (BGP), or UDP 4789 (VXLAN), or IP-in-IP (protocol 4, not a port)
CiliumUDP 8472 (VXLAN) or UDP 6081 (Geneve), TCP 4240 (health)
Weave NetTCP 6783, UDP 6783-6784

These are easy to forget because they are not on the Kubernetes page. The symptom is specific: Pods on the same node can reach each other, Pods on different nodes cannot. Check the plugin's own documentation for the list.

The three address ranges

Three address ranges, three ownersprovidesbuildsimplementsNode network192.168.56.0/24Pod network10.244.0.0/16Service network10.96.0.0/12You or the cloudreal interfacesCNI pluginone slice per nodekube-proxyrules, no interface
Three address ranges, three owners. The node network is real and yours to provide. The Pod network is built by the CNI plugin. The Service network is virtual: kube-proxy makes its addresses work, and no interface carries them.

Parts:

  • Node network (192.168.56.0/24)
  • Pod network (10.244.0.0/16)
  • Service network (10.96.0.0/12)
  • You or the cloud (real interfaces)
  • CNI plugin (one slice per node)
  • kube-proxy (rules, no interface)

Connections:

  • You or the cloud to Node network: provides
  • CNI plugin to Pod network: builds
  • kube-proxy to Service network: implements
RangeExampleWho assigns addressesWhere it is configured
Node network192.168.56.0/24You, DHCP or the cloudOutside Kubernetes
Pod network (cluster CIDR)10.244.0.0/16The CNI plugin's IPAMkubeadm init --pod-network-cidr, --cluster-cidr on the controller manager, and the plugin's own configuration
Service network10.96.0.0/12The API serverkubeadm init --service-cidr, --service-cluster-ip-range on the API server

The node network is the only one with real interfaces behind it from the start. The Pod network exists once a CNI plugin is installed. The Service network never appears on any interface: a Service address is only a match in the rules that kube-proxy writes on every node.

Two rules follow:

  • The ranges must not overlap, with each other or with networks the nodes must reach (your office network, a VPN, a database subnet). If the Pod range covers the node range, a node cannot tell whether an address is a Pod or another node.
  • The Pod range given to kubeadm must match the plugin. With --pod-network-cidr=10.244.0.0/16, the controller manager gives every node a slice of it (10.244.0.0/24, 10.244.1.0/24, ...) in spec.podCIDR. Plugins such as Flannel use those slices. Others keep their own pools, and then their configuration must use the same range.

Without any CNI plugin, a new cluster has no Pod network. The nodes stay NotReady and CoreDNS stays Pending until you install one. That is the normal state right after kubeadm init, not a fault.

Four problems, four answers

"Kubernetes networking" is really four different questions:

Four networking problems, four answersviaviaviaviaContainers in a Podsame PodPod to Podany nodePod to Servicestable name and IPOutside to Serviceusers, other systemslocalhostshared namespaceCNI pluginthe Pod networkkube-proxy and DNSClusterIPNodePort, GatewayLoadBalancer, Ingress
Four networking problems, four answers. Cluster networking is not one mechanism. Each kind of traffic is handled by a different part, and each part has its own lesson in this section.

Parts:

  • Containers in a Pod (same Pod)
  • Pod to Pod (any node)
  • Pod to Service (stable name and IP)
  • Outside to Service (users, other systems)
  • localhost (shared namespace)
  • CNI plugin (the Pod network)
  • kube-proxy and DNS (ClusterIP)
  • NodePort, Gateway (LoadBalancer, Ingress)

Connections:

  • Containers in a Pod to localhost: via
  • Pod to Pod to CNI plugin: via
  • Pod to Service to kube-proxy and DNS: via
  • Outside to Service to NodePort, Gateway: via
TrafficHow it is solvedLessons
Container to container in one PodThey share one network namespace, so localhost worksPod Networking
Pod to Pod, on any nodeEvery Pod has a unique IP, and the CNI plugin makes all of them reachable without NATPod Networking, CNI in Kubernetes
Pod to ServiceA stable virtual IP and DNS name in front of changing Pods, implemented by kube-proxy and CoreDNSService Networking, DNS in Kubernetes
Outside to ServiceNodePort, LoadBalancer, Ingress or the Gateway APIIngress, Gateway API

When something does not connect, the first step is to decide which of the four it is. Each has different parts and different places to look.

Using it

Example · Check a machine before it joins the cluster

hostname
ip -br link | grep -v '^lo'
sudo cat /sys/class/dmi/id/product_uuid
sysctl net.ipv4.ip_forward
nc -zv 192.168.56.11 6443
node02
eth0             UP             08:00:27:4c:19:a3 <BROADCAST,MULTICAST,UP,LOWER_UP>
7C2D4B8E-1F0A-4E55-9B3D-2A6C91E0F7D4
net.ipv4.ip_forward = 1
Connection to 192.168.56.11 6443 port [tcp/*] succeeded!

Compare the name, the MAC address and the UUID with the existing nodes: all three must be different. The last line proves that this machine can reach the API server, which is all kubeadm join needs from the network.

Example · Find which component owns a port

A question asks: "On which port does the kube-scheduler listen on the control plane node?"

sudo ss -tlnp | grep kube-scheduler
LISTEN 0  4096  127.0.0.1:10259  0.0.0.0:*  users:(("kube-scheduler",pid=1398,fd=3))

The flags mean: -t TCP, -l listening sockets only, -n numbers instead of service names, -p the owning process (needs root). The answer is 10259, bound to localhost.

The reverse question, "what is listening on 10250?", is the same command with grep 10250.

Example · A node is NotReady after a firewall change

kubectl get nodes
NAME           STATUS     ROLES           AGE   VERSION
controlplane   Ready      control-plane   12d   v1.37.0
node01         NotReady   <none>          12d   v1.37.0

On node01, the kubelet's log shows what it cannot do:

sudo journalctl -u kubelet -n 3 --no-pager
"Unable to register node with API server" err="Post \"https://192.168.56.11:6443/api/v1/nodes\": dial tcp 192.168.56.11:6443: i/o timeout"

A timeout means packets are dropped on the way, which points to a firewall. (Connection refused would mean the packet arrived and nothing listens.) Test and fix on the control plane node:

nc -zv -w 2 192.168.56.11 6443               # from node01: times out
sudo firewall-cmd --list-ports               # on controlplane: 6443/tcp is missing
sudo firewall-cmd --permanent --add-port=6443/tcp --add-port=10250/tcp
sudo firewall-cmd --reload

On Ubuntu the firewall tool is ufw (sudo ufw allow 6443/tcp). In a cloud, the same rule lives in the security group of the instances.

Example · Read the three ranges from a running cluster

kubectl get nodes -o custom-columns=NAME:.metadata.name,IP:.status.addresses[0].address,PODCIDR:.spec.podCIDR
sudo grep -E 'cluster-cidr|service-cluster-ip-range' /etc/kubernetes/manifests/*.yaml
NAME           IP              PODCIDR
controlplane   192.168.56.11   10.244.0.0/24
node01         192.168.56.21   10.244.1.0/24

/etc/kubernetes/manifests/kube-apiserver.yaml:    - --service-cluster-ip-range=10.96.0.0/12
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --cluster-cidr=10.244.0.0/16
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --service-cluster-ip-range=10.96.0.0/12

Nodes on 192.168.56.0/24, Pods on 10.244.0.0/16 with a /24 per node, Services on 10.96.0.0/12. No overlap.

Tricks

Common mistakes

  • Cloning virtual machines and joining them unchanged. The clones share host name, MAC address and product_uuid. Change all three before kubeadm join.
  • Opening 6443 and forgetting 10250. The cluster looks healthy until someone runs kubectl logs or kubectl exec.
  • Opening the Kubernetes ports and forgetting the CNI plugin's ports. Pods on different nodes cannot reach each other.
  • Choosing a Pod range that overlaps the node network or the Service range. Routing becomes ambiguous and fails in confusing ways.
  • Giving kubeadm one Pod range and the plugin another. Pods get addresses the rest of the cluster does not expect.
  • Expecting to ping a Service address. A ClusterIP is not on any interface. Only the Service's ports are handled, so test it with curl or nc, not ping.
  • Reading a NotReady node right after kubeadm init as a broken node. Without a CNI plugin every node is NotReady.

Recap

  • Every node needs an address the others can reach, a unique host name, MAC address and product_uuid, IPv4 forwarding and open ports.
  • Control plane: 6443 API server, 2379-2380 etcd, 10250 kubelet, 10259 scheduler, 10257 controller manager.
  • Workers: 10250 kubelet, 10256 kube-proxy, 30000-32767 NodePort Services.
  • Everything connects to the API server on 6443, and the API server calls back to kubelets on 10250.
  • A cluster has a node range, a Pod range and a Service range. They must not overlap, and the Pod range must match the CNI plugin.
  • Networking is four problems: inside a Pod, Pod to Pod, Pod to Service, outside to Service.

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.