Skip to content

// cheat sheets / kubernetes-networking

Kubernetes networking

How a request finds a pod: pod IPs, Services, DNS, Ingress and NetworkPolicy

ConceptsIntermediate#kubernetes#networking#kubectl

1. Pod-to-pod networking

  • Pod IP — Every pod gets its own IP address, shared by all the containers in it.
  • No NAT — Pods reach each other directly by pod IP, on the same node or another.
  • localhost — Containers in one pod share the network, so they talk over localhost.
  • CNI plugin — Calico, Cilium, Flannel and others make the pod network work.
Diagram for Pod-to-pod networking: Pod A → Pod B (pod IP): Pod A in Node 1; Pod B in Node 2.
Open this diagram in archhy

Every pod has its own IP, but pods come and go: never hard-code one.

2. Service types

TypeWhat it gives you
ClusterIPThe default: a stable virtual IP reachable only inside the cluster.
NodePortThe Service on a port (30000–32767 by default) of every node.
LoadBalancerA cloud load balancer in front, with an external IP.
ExternalNameA DNS alias (CNAME) to a name outside the cluster; no proxying.
HeadlessclusterIP: None. DNS returns the pods' own IPs instead of one virtual IP.
Diagram for Service types: Client pod → my-svc; my-svc → Pod 1; my-svc → Pod 2; my-svc → Pod 3.
Open this diagram in archhy

A Service picks its pods by label selector and spreads traffic across the ready ones.

3. Cluster DNS

  • CoreDNS — The cluster's DNS server; every pod is set up to ask it first.
  • my-svc.my-namespace.svc.cluster.local — A Service's full name.
  • Short names — Inside the same namespace, my-svc on its own is enough.
  • Headless Services — Return one record per ready pod, so clients can pick a pod.

Call Services by name, never by IP: names survive a redeploy.

4. Ingress

  • Rules — Route HTTP and HTTPS by host name and path to Services.
  • Controller — An Ingress does nothing until an ingress controller runs in the cluster.
  • TLS — Certificates come from a Secret named in the Ingress.
  • ingressClassName — Says which controller should handle this Ingress.
  • Gateway API — The newer, more expressive way to route traffic into a cluster.
Diagram for Ingress: Users → Ingress (HTTPS); Ingress → web (/); Ingress → api (/api).
Open this diagram in archhy

Ingress is for HTTP(S); for other protocols use a LoadBalancer Service.

5. NetworkPolicy

  • Open by default — With no policy, every pod accepts traffic from anywhere.
  • Selected pods — Once a policy selects a pod, only the traffic it allows gets in (or out).
  • Selectors — Allow by podSelector, namespaceSelector, ipBlock and port.
  • Enforcement — Your CNI plugin must support NetworkPolicy, or policies are ignored.
Diagram for NetworkPolicy: frontend → allow from frontend (allowed); allow from frontend → backend.
Open this diagram in archhy

Start with a default-deny policy per namespace, then allow what each app needs.

6. Debugging commands

CommandWhat it shows
kubectl get svc -AEvery Service, its type, cluster IP and ports.
kubectl get endpointslices -l kubernetes.io/service-name=my-svcThe pod IPs behind a Service.
kubectl describe ingress my-ingressIts rules, backends and recent events.
kubectl port-forward svc/my-svc 8080:80Reach a Service from your machine on localhost:8080.
kubectl get networkpolicy -AEvery NetworkPolicy, by namespace.

No endpoints means the selector matches no ready pod: check labels and readiness.

archhyarchhy.com/cheat-sheets/kubernetes-networkingMake your own at archhy.com

Draw your own, with real cloud icons.

Start drawing, free

No account needed to start.