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.
| Kind | Ranges | Like |
|---|---|---|
| Private | 10.x.x.x, 172.16–31.x.x, 192.168.x.x | Room numbers inside an office: only meaningful inside. Your laptop, your containers, and all Pods use these. |
| Public | Everything else, e.g. 140.82.112.6 | A real street address anyone on the internet can reach. |
| Loopback | 127.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.
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.
| Range | Fixed part | Size | Means |
|---|---|---|---|
10.0.0.0/8 | 10.x.x.x | 16.7 million | Everything starting with 10 |
10.244.0.0/16 | 10.244.x.x | 65,536 | Everything starting with 10.244 |
10.244.1.0/24 | 10.244.1.x | 256 | Everything starting with 10.244.1 |
10.244.1.15/32 | all of it | 1 | Exactly 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.
- Which DNS server to ask is written in
/etc/resolv.conf. - "Could not resolve host" /
ENOTFOUND= the phone book has no such name. The network itself may be fine. - Try it:
nslookup api.github.com
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
- Load balancer: one address in front of several copies; spreads the requests. Can work on raw connections (layer 4: IP + port).
- Reverse proxy: reads the HTTP request (layer 7) and chooses by host name or path:
/posts→ posts,/comments→ comments. Nginx is the classic one. Often it load-balances too.
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:
getaddrinfo ENOTFOUND posts-srvDNS has no such name. No packet was even sent. Check spelling and namespace.
ECONNREFUSED 10.244.1.15:4000The machine answered instantly: "nothing on that port". Wrong port, app not started, or listening on 127.0.0.1.
ETIMEDOUTafter 30 secondsNo answer at all. A firewall or network policy silently drops packets, or no route to that address.
| Error | Means | Speed |
|---|---|---|
| not found / could not resolve | DNS: no such name | Fast |
| connection refused | Reached the machine, nothing listening on that port | Instant |
| timeout | Packets lost: blocked, or no route | Slow (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).
A Pod is exactly one network namespace. Keep this picture; the next chapter builds on it.
Recap
| Idea | In one line |
|---|---|
| IP address | Which machine |
| Port | Which program on it |
| 127.0.0.1 vs 0.0.0.0 | Listen for myself only vs for everyone |
CIDR /16, /24 | A range: how much of the address is fixed |
| DNS | Name → IP, before connecting |
| Gateway / route | Where to send packets for other networks |
| NAT | Rewriting addresses on the way through |
| Load balancer / reverse proxy | One front door, many copies behind it |
| Refused / timeout / not found | Nobody listening / blocked / no such name |
| Network namespace | A 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.