Appearance

Networking before Kubernetes

Follow DNS, TCP ports, and HTTP across a container network boundary.

What you will understand

  • Distinguish port declarations from actual listeners
  • Trace DNS resolution before an HTTP request
  • Explain loopback and host port publishing

Builds on: Images and registries

Mental model: name, address, connection, message

A web request crosses several boundaries. DNS turns a hostname into address information. Routing determines how packets reach an address. In the TCP-based HTTP examples used here, TCP establishes a connection between address-and-port pairs, and HTTP carries application messages over it; HTTPS adds TLS. HTTP/3 instead uses QUIC over UDP, so TCP is not a universal HTTP requirement. These steps can fail independently. A correct DNS answer does not prove that a server is listening, and a successful connection does not prove that the requested HTTP path exists.

A port identifies a transport endpoint within a network namespace, not a physical opening in a container. A server must bind an address and port. Binding 127.0.0.1:8080 normally accepts connections only over that network namespace’s loopback interface. Binding 0.0.0.0:8080 accepts connections on all local IPv4 interfaces, subject to networking and policy. IPv6 listeners and dual-stack behavior need deliberate configuration; do not infer them from an IPv4 example.

Two containers with separate network namespaces can each listen on port 80 without conflict. Two processes sharing one network namespace cannot usually bind the same address, port, and protocol simultaneously. This becomes important when multiple containers share a Pod’s network namespace: they reach each other through localhost, and their listening ports must coexist.

Ports are endpoints, not declarations

Follow one HTTP request through a published local port.

Flow viewStep 1 of 3
The server listensnginx binds container TCP 80. Declaring a port would not start this listener.. Laptop 127.0.0.1, ready. Host 8080 → container 80, active. nginx listens on :80, readyLaptop 127.0.0.1
Laptop 127.0.0.1Ready
Host 8080 → container 80
Host 8080 → container 80In focus
nginx listens on :80
nginx listens on :80Ready
Laptop 127.0.0.1Ready
Host 8080 → container 80In focus
nginx listens on :80Ready
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: loopback-only server
The server listens

nginx binds container TCP 80. Declaring a port would not start this listener.

Read the complete visual sequence
  1. The server listens

    nginx binds container TCP 80. Declaring a port would not start this listener.

  2. Connect, then speak HTTP

    curl connects to host port 8080. Forwarding delivers the connection to the container listener, and HTTP carries GET / over it.

  3. A response is application evidence

    HTTP 200 shows a server handled the request. HTTP 404 would still show a working connection and a missing application path.

Failure: loopback-only server

Failure: loopback-only server

  1. Listen on the wrong interface

    A server binds only 127.0.0.1 inside its container. External traffic targets the container interface address.

  2. No HTTP response exists

    The request cannot reach a listener at that destination. A port declaration does not change the bind address.

  3. Align the bind address

    Configure the intended server interface and port, then retest connectivity before diagnosing an HTTP path.

About this model

Docker publishes only IPv4 loopback 8080 to container TCP 80; Kubernetes Services are introduced later.

Walkthrough: publish a local training port

This optional exercise uses Docker, not a Kubernetes Service. It makes the network boundary visible before the cluster adds more layers. Docker must already be installed; the nginx image is a training dependency. Use Docker Engine 28.0.0 or later for the documented loopback-only exposure behavior: older releases can allow hosts on the same layer-2 network to reach ports published to localhost.

# Bind only the laptop's IPv4 loopback address for this local exercise.
# Host TCP 8080 forwards to the container's TCP 80.
docker run --rm -d --name network-demo \
  -p 127.0.0.1:8080:80 nginx:1.27.5
# Show HTTP response headers plus the response body.
curl -i http://127.0.0.1:8080/
# Ask for a path nginx does not serve.
curl -i http://127.0.0.1:8080/does-not-exist
# Release the published host port.
docker stop network-demo

The first request should receive an HTTP success response if the container starts and the port is available. The second typically receives HTTP 404. Both responses prove that a server answered the connection. “Connection refused” is different: the requested transport endpoint rejected the connection before an HTTP response existed. A timeout indicates that an expected response did not arrive; filtering, routing problems, an unresponsive server, and other causes require further evidence.

An image’s EXPOSE instruction or Kubernetes containerPort field does not publish a host port or create a listener. A manifest can document port 80 while the process actually listens on 8080. Follow the process configuration and the forwarding configuration separately. Kubernetes later replaces manual Pod-address tracking with Services, without changing this basic requirement.

DNS happens before the request

For a URL such as http://shop.example.test:8080/catalog, the client extracts the hostname, resolves it using its resolver configuration, connects to an address on port 8080, and sends an HTTP request for /catalog. The hostname can also matter at the application layer through HTTP authority or Host information and, for HTTPS, TLS server name selection. Replacing a hostname with an IP can therefore change more than just DNS.

Resolve before connecting

Separate DNS answers, transport connections, and HTTP messages.

Flow viewStep 1 of 3
Resolve the URL hostnameThe resolver asks DNS for address information for shop.example.test. No HTTP request has reached the web application yet.. URL hostname, active. DNS resolver, active. Address record, idleURL hostname
URL hostnameIn focus
DNS resolver
DNS resolverIn focus
Address record
Address recordContext
URL hostnameIn focus
DNS resolverIn focus
Address recordContext
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: DNS succeeds, listener absent
Resolve the URL hostname

The resolver asks DNS for address information for shop.example.test. No HTTP request has reached the web application yet.

Read the complete visual sequence
  1. Resolve the URL hostname

    The resolver asks DNS for address information for shop.example.test. No HTTP request has reached the web application yet.

  2. Connect to address and port

    The client uses the returned address and explicit TCP port 8080. DNS does not verify the target listener.

  3. Send the HTTP message

    Only after connection setup does the client exchange HTTP request and response data. The hostname can still influence application routing.

Failure: DNS succeeds, listener absent

Failure: DNS succeeds, listener absent

  1. DNS returns an address

    The name resolves successfully. This proves a naming step worked, not that the application is available.

  2. The destination refuses TCP

    No intended listener accepts port 8080 at that address. HTTP has not started.

  3. Investigate the listener

    Compare the resolved address, URL port, server binding, and forwarding rules. Retain the successful DNS result as evidence.

About this model

A client obtains one IPv4 address; caching, IPv6 racing, and TLS details are simplified.

# This requires nslookup on your machine; any legitimate DNS answer may change.
nslookup kubernetes.io
# Verbose output separates connection setup from the HTTP response.
curl -v https://kubernetes.io/ -o /dev/null

DNS answers can be cached according to their TTL and resolver behavior. An application may keep using an existing TCP connection after a DNS record changes, so a DNS update does not forcibly migrate every active request. A records carry IPv4 addresses, AAAA records carry IPv6 addresses, and CNAME records refer to another DNS name. No DNS record makes a backend healthy by itself.

Practice: predict the first broken boundary

Draw a four-step path for a request: resolve, connect, negotiate TLS if applicable, exchange HTTP. For each symptom, identify the earliest step that must have succeeded. An HTTP 500 means an HTTP-speaking component answered; it does not identify whether the fault originated in that server or an upstream dependency. A certificate-name error usually means name resolution and some connection establishment already happened. A DNS “name does not exist” result prevents ordinary connection setup to that name.

Pitfalls

localhost always refers to the caller’s own network namespace. From a laptop it is the laptop, from a Pod it is that Pod. A port-forward or host publishing rule deliberately bridges a boundary. Do not assume those bridges exist merely because two tools use the same port number.

Check your understanding

A DNS lookup succeeds but curl reports connection refused. Should you change the DNS name first?

First inspect the address, destination port, server listener, and forwarding path. The successful lookup supplied address information; refusal occurs at a later boundary. DNS may still have supplied the wrong address, but changing names without checking the listener discards useful evidence. Test the exact address and port, then compare them with the server’s bind configuration.

Use the module lab to compare a successful HTTP response, an HTTP error response, and a transport failure before moving into cluster components.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.