Kubernetes networking: pods, Services, DNS, Ingress and Gateway API

ExplainedKubernetesDevOps, Hands OnBy Cloud Hands On

How a request finds its way to a pod, from outside the cluster and from pod to pod.

Every pod gets its own IP address, and every pod can reach every other pod directly, across nodes, unless a NetworkPolicy says otherwise. A network plugin (the CNI, such as Azure CNI, Cilium or kind's kindnet) makes that work.

Because pod IPs change, apps talk to Services: a stable virtual IP and DNS name (orders.shop.svc.cluster.local) in front of the pods a selector matches. kube-proxy (or the CNI) turns traffic to the Service IP into traffic to one of the pods. CoreDNS answers the names.

Traffic from outside comes through a LoadBalancer Service, an Ingress (host and path rules, read by an ingress controller), or the newer Gateway API (Gateway plus HTTPRoute objects, split by role, with traffic splitting built in). The ingress-nginx controller has been retired by its maintainers, so new designs should prefer the Gateway API or a supported controller.

Cost. Free to learn on kind. In a cloud, load balancers and public IPs created by Services and gateways are charged.

Use it when

How it works

Pod network
Every pod has an IP; the CNI connects them across nodes.
Service
A stable IP and name; the selector picks the pods; EndpointSlices list them.
DNS
CoreDNS answers service names; the namespace is part of the name.
Entry points
LoadBalancer Services, Ingress or Gateway API bring outside traffic in.
NetworkPolicy
Allow-lists for pod traffic; once a pod is selected, everything else is denied.

Options

ClusterIP
Inside the cluster only (the default).
NodePort
A port on every node; mostly for testing.
LoadBalancer
One cloud load balancer per Service.
Gateway API
One shared entry point with routes per team.

Example. SS Kaiser's shop moved from five LoadBalancer Services (five public IPs) to one shared Gateway with five HTTPRoutes, which cut costs and put all certificates in one place.

Don't confuse it with

Ingress
Older and simpler; extra features needed controller-specific annotations.
Service mesh
Adds encryption, retries and traffic rules between services, at the cost of more moving parts.

Words to know

CNI
The network plugin that gives pods their IPs and connects them.
kube-proxy
Turns Service IPs into traffic to real pods.
CoreDNS
The cluster's DNS server.
NetworkPolicy
Rules that allow traffic to and from selected pods.

Where to look

  1. kubectl get svc,endpointslices
  2. kubectl get gateway,httproute

Practise it

Read it in the guide, next to the tasks and labs.

Open in DevOps, Hands On

Keep going