Chapter 24 of 47 · Networking, part 1

Networking basics you need first

Most Kubernetes networking confusion is really about a few plain networking ideas. This chapter explains them with everyday comparisons and no Kubernetes at all. The next chapter shows where each one appears inside a cluster.

1 · IP address: the building's street address

Every machine (or container, or Pod) on a network has an IP address, four numbers from 0 to 255: 10.244.1.15. It says which machine to deliver to.

KindRangesLike
Private10.x.x.x, 172.16–31.x.x, 192.168.x.xRoom numbers inside an office: only meaningful inside. Your laptop, your containers, and all Pods use these.
PublicEverything else, e.g. 140.82.112.6A real street address anyone on the internet can reach.
Loopback127.0.0.1 (localhost)"Myself". Never leaves the machine.

2 · Port: the flat number in the building

One machine runs many programs. The port (0–65535) says which program gets the message. Address + port together: 10.244.1.15:4000.

One IP, many ports Machine 10.244.1.15 :4000posts app :5432PostgreSQL :22SSH 10.244.1.15:4000 Common ports: 80 HTTP · 443 HTTPS · 53 DNS · 5432 Postgres · 6379 Redis

Only one program per port per address. A second one gets EADDRINUSE (you saw this in chapter 6).

3 · localhost and 0.0.0.0: who may knock

When a server starts, it chooses which of its addresses to listen on. This one setting causes a huge number of "works on my machine, not in the container" bugs. Switch between the two:

127.0.0.1 / localhost

"Only talk to me from inside this same machine." Fine on your laptop, useless in a container that others must reach.

0.0.0.0

"Accept on every address I have." Not an address you can call; it is a listening instruction. Use it for servers in containers.

// Express defaults to all addresses, so this is fine:
app.listen(4000);
// This breaks in Kubernetes:
app.listen(4000, '127.0.0.1');

4 · IP ranges (CIDR): a whole street at once

Networks are described as ranges, written like 10.244.0.0/16. The number after the slash says how much of the address is fixed. The rest can vary. Bigger number after the slash = smaller range.

RangeFixed partSizeMeans
10.0.0.0/810.x.x.x16.7 millionEverything starting with 10
10.244.0.0/1610.244.x.x65,536Everything starting with 10.244
10.244.1.0/2410.244.1.x256Everything starting with 10.244.1
10.244.1.15/32all of it1Exactly this one address

Check some addresses yourself:

Why you care: a cluster gives Pods one range, Services another, and each node a slice of the Pod range. Seeing 10.244.2.7 you can tell at a glance "that is a Pod on node 2".

5 · DNS: the phone book

People remember names, networks need numbers. DNS turns a name into an IP address, before any connection is made.

A DNS lookup before connecting Your app DNS serverthe phone book api.github.com140.82.112.6 1 · api.github.com? 2 · 140.82.112.6 3 · connect to 140.82.112.6:443

6 · Routing and the gateway: the post office

If the destination is on my own network (inside my range), I deliver it directly. If not, I hand it to the gateway (a router), which knows where to forward it next. A routing table is the list of "for this range, go via there" rules.

$ ip route
default via 192.168.1.1 dev eth0          # everything else → the gateway
192.168.1.0/24 dev eth0                   # my own network → deliver directly
10.244.2.0/24 via 192.168.1.12            # Pods of node 2 → send to node 2

That last line is exactly how many clusters reach Pods on other nodes.

7 · NAT: one front desk for many rooms

Network Address Translation rewrites addresses on the way through. Two everyday forms:

Many inside → one outside

Your home router: every device has a private 192.168 address, but the internet sees only the router's one public IP. The router remembers who asked what and passes answers back.

Port forwarding

"Anything arriving at port 8080 here goes to 172.17.0.2:80." That is what docker run -p 8080:80 did, and what a Kubernetes Service does to reach a Pod.

8 · Load balancer and reverse proxy: the receptionist

A load balancer spreads requests over copies Clients Load balancerone address copy 1 copy 2 copy 3

In Kubernetes: a Service is a layer-4 load balancer; an Ingress is a layer-7 reverse proxy.

9 · Refused, timeout, not found: three different problems

The error message tells you where it broke. Learn these three and debugging gets much faster:

ErrorMeansSpeed
not found / could not resolveDNS: no such nameFast
connection refusedReached the machine, nothing listening on that portInstant
timeoutPackets lost: blocked, or no routeSlow (waits, then gives up)

10 · Network namespaces: a private network kit per container

Linux can give a process its own network namespace: its own IP, its own ports, its own localhost, its own routing table (Docker chapter 7). A veth pair is a virtual cable connecting that namespace to the host; a bridge is a virtual switch joining many cables (Docker chapter 10).

Namespaces connected by veth pairs to a bridge one machine namespace Aeth0 10.244.1.15 namespace Beth0 10.244.1.16 vethveth bridge (virtual switch)

A Pod is exactly one network namespace. Keep this picture; the next chapter builds on it.

Recap

IdeaIn one line
IP addressWhich machine
PortWhich program on it
127.0.0.1 vs 0.0.0.0Listen for myself only vs for everyone
CIDR /16, /24A range: how much of the address is fixed
DNSName → IP, before connecting
Gateway / routeWhere to send packets for other networks
NATRewriting addresses on the way through
Load balancer / reverse proxyOne front door, many copies behind it
Refused / timeout / not foundNobody listening / blocked / no such name
Network namespaceA private network stack; one per Pod

Networking basics: common questions

What is the difference between 127.0.0.1 and 0.0.0.0?

127.0.0.1 only accepts connections from the same machine or container. 0.0.0.0 tells a server to listen on all its addresses, which is what a server in a container needs.

What is the difference between connection refused and timeout?

Refused means the machine was reached but nothing listens on that port. Timeout means no answer at all, usually a firewall or a missing route.