Kubernetes Traffic Flow
Kubernetes traffic falls into two broad categories: traffic coming in from outside the cluster and traffic moving between services inside the cluster.
The Big Picture
External User │ ▼[ LoadBalancer / Ingress ] │ ▼[ Service ] │ ▼[ Pod (via kube-proxy / iptables / eBPF) ] │ ▼[ Container ]
1. External Traffic (North-South)
This is traffic entering the cluster from the outside world.
LoadBalancer Service
The simplest path. A cloud provider provisions an external LB that forwards traffic directly to a Kubernetes Service.
Internet → Cloud LB → NodePort (on any node) → Service → Pod
Ingress
A more sophisticated HTTP/HTTPS router. An Ingress Controller (e.g. NGINX, Traefik, AWS ALB) watches Ingress resources and routes based on host/path rules.
Internet → Cloud LB → Ingress Controller Pod → Service → Pod
# Example Ingress rulespec: rules: - host: app.example.com http: paths: - path: /api backend: service: name: api-service port: number: 80 - path: /web backend: service: name: web-service port: number: 80
Service Types for External Access
| Type | How it works |
|---|---|
ClusterIP | Internal only, no external access |
NodePort | Opens a port (30000–32767) on every node |
LoadBalancer | Provisions a cloud LB, routes to NodePort → Service |
ExternalName | DNS alias to an external hostname |
2. Internal Traffic (East-West)
Traffic between services inside the cluster.
The Role of kube-proxy
Every node runs kube-proxy, which programs iptables (or IPVS) rules. When a pod calls a Service ClusterIP, iptables intercepts the packet and rewrites the destination to one of the healthy pod IPs (load balancing happens here).
Pod A → Service ClusterIP → iptables/IPVS → Pod B (one of N replicas)
DNS Resolution
Every pod gets DNS from CoreDNS. A service named api in namespace default is reachable at:
api # within same namespaceapi.default # short formapi.default.svc.cluster.local # fully qualified
Pod-to-Pod (direct)
Every pod gets its own IP (flat network). Pods can talk directly without NAT — this is the Kubernetes networking model. Implemented by the CNI plugin (Flannel, Calico, Cilium, etc.).
Pod A (10.244.1.5) → Pod B (10.244.2.8) # direct, no NAT
3. The Full Request Lifecycle (example)
A user hits https://app.example.com/api/users:
1. DNS resolves app.example.com → Cloud LB IP2. Cloud LB receives request on port 443 → forwards to Ingress Controller pod (e.g. nginx on port 443)3. Ingress Controller terminates TLS → matches rule: host=app.example.com, path=/api → forwards to Service "api-service:80"4. CoreDNS resolves "api-service" → ClusterIP (e.g. 10.96.45.12)5. iptables on the node intercepts packet to 10.96.45.12 → rewrites destination to a healthy pod IP (e.g. 10.244.2.7:8080) → load balances across replicas6. Packet reaches Pod → container handles request on port 80807. Response travels back the same path in reverse
4. Network Policies
By default, all pods can talk to all other pods. NetworkPolicy resources let you lock this down:
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: api-allow-only-frontendspec: podSelector: matchLabels: app: api ingress: - from: - podSelector: matchLabels: app: frontend ports: - port: 8080
This says: only pods labeled app=frontend can reach app=api on port 8080. All other ingress is dropped.
5. Service Mesh (Advanced)
Tools like Istio or Linkerd inject a sidecar proxy (Envoy) into every pod. Traffic flows through the sidecar, enabling:
Pod A → Envoy sidecar → mTLS encrypted tunnel → Envoy sidecar → Pod B
| Feature | Without mesh | With mesh |
|---|---|---|
| Encryption | Manual TLS setup | Automatic mTLS |
| Retries/timeouts | App code | Proxy config |
| Traffic splitting | Needs ingress tricks | Native (canary, A/B) |
| Observability | Limited | Full traces, metrics |
Key Components Summary
| Component | Role |
|---|---|
| CoreDNS | Service discovery via DNS |
| kube-proxy | Programs iptables/IPVS rules for Service routing |
| CNI plugin | Pod-to-pod networking (Flannel, Calico, Cilium) |
| Ingress Controller | HTTP routing, TLS termination |
| Cloud LB | External entry point |
| NetworkPolicy | Firewall rules between pods |
| Service Mesh | mTLS, observability, advanced traffic control |