✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes Networking Areas

Kubernetes Networking Areas cover how containers communicate within and across clusters, ensuring reliable and secure network connectivity in containerized environments.

Kubernetes Networking Areas is the collective term for the distinct problem domains that a Kubernetes cluster's networking model must address so that pods, services, nodes, and external clients can communicate reliably. Rather than being a single mechanism, Kubernetes networking is composed of several cooperating layers, each responsible for a specific scope of traffic: pod-to-pod communication, service discovery and load balancing, ingress from outside the cluster, egress to external systems, name resolution, and policy-based traffic control. Understanding these areas separately is essential for diagnosing connectivity issues, designing secure topologies, and selecting the right plugins and controllers for a given cluster.


Pod Networking

The Flat Network Model

Kubernetes requires that every pod be assigned its own IP address and that this IP be reachable from every other pod in the cluster without Network Address Translation (NAT). This is often called the "IP-per-pod" model. It simplifies application design because pods can communicate as if they were separate hosts on a flat network, with no need to manage port mappings.

Container Network Interface (CNI)

The actual wiring of pod IPs onto the underlying infrastructure is delegated to a CNI plugin (Calico, Cilium, Flannel, Weave, or cloud-provider-native implementations such as AWS VPC CNI or Azure CNI). The kubelet invokes the CNI plugin whenever a pod is created or destroyed, and the plugin is responsible for allocating an IP, attaching a virtual interface to the pod's network namespace, and configuring routes so traffic can leave and enter the pod.

Overlay vs. Underlay Networks

Some CNI plugins implement an overlay network, encapsulating pod traffic inside protocols such as VXLAN or IP-in-IP so it can traverse infrastructure that has no native awareness of pod IPs. Others operate at the underlay level, programming routes directly into the physical or virtual network fabric (BGP-based routing, for example) for lower overhead and better observability, at the cost of tighter coupling to the underlying infrastructure.


Service Networking

ClusterIP and Virtual IPs

A Kubernetes Service provides a stable virtual IP (ClusterIP) that abstracts away the changing set of pod IPs behind a label selector. Requests sent to the ClusterIP are transparently load-balanced across the healthy pods backing the service.

kube-proxy and Traffic Modes

The component historically responsible for implementing this virtual IP is kube-proxy, which can operate in several modes:

  • iptables mode: programs Netfilter rules to redirect and load-balance traffic, offering simplicity but with performance that degrades as the number of services grows.
  • IPVS mode: uses the Linux IP Virtual Server subsystem for more efficient load balancing at scale, supporting additional algorithms such as round-robin, least connection, and destination hashing.
  • eBPF-based dataplanes: increasingly, CNI plugins such as Cilium replace kube-proxy entirely with eBPF programs attached to kernel hooks, reducing latency and improving observability.

Headless Services

When load balancing is not desired and clients need to discover individual pod IPs directly (common with stateful applications), a headless Service (clusterIP: None) can be used, causing DNS queries to return the full set of pod IPs instead of a single virtual IP.


DNS and Service Discovery

CoreDNS

Kubernetes clusters run an internal DNS service, typically CoreDNS, which watches the API server for Services and Endpoints and generates DNS records automatically. Pods are configured (via /etc/resolv.conf) to resolve names such as my-service.my-namespace.svc.cluster.local to the corresponding ClusterIP.

Service Discovery Patterns

Applications rely on this DNS-based discovery rather than hardcoded IPs, allowing services to be rescheduled, scaled, or replaced without requiring configuration changes in the clients that consume them.


Ingress and North-South Traffic

Ingress Resources and Controllers

While Services handle internal (east-west) traffic, external (north-south) access into the cluster is typically managed through an Ingress resource, which defines HTTP and HTTPS routing rules (host- and path-based). An Ingress Controller (such as NGINX Ingress, Traefik, HAProxy, or a cloud load balancer integration) watches these resources and configures an actual proxy or load balancer to implement them.

Gateway API

The Gateway API is a newer, more expressive successor to Ingress, introducing role-oriented resources (GatewayClass, Gateway, HTTPRoute, and others) that separate infrastructure concerns from application routing concerns and support protocols beyond HTTP.

LoadBalancer and NodePort Services

For non-HTTP traffic or simpler exposure needs, a Service can be published as a NodePort (opening a static port on every node) or as a LoadBalancer (provisioning an external load balancer through the cloud provider's integration).


Network Policies and Security

Default Allow-All Behavior

By default, Kubernetes allows all pods to communicate with all other pods with no restrictions. This flat trust model is often unsuitable for production environments handling sensitive workloads.

NetworkPolicy Resources

A NetworkPolicy object allows administrators to define ingress and egress rules scoped to pods matching a label selector, restricting traffic to specific namespaces, pod selectors, IP blocks, and ports. Enforcement of NetworkPolicy objects depends entirely on the CNI plugin in use; not all plugins implement the NetworkPolicy API, and those that do vary in the granularity and protocols they support (some, such as Cilium, extend the model with Layer 7 policies).

Zero-Trust and Service Mesh Security

For finer-grained security, many clusters adopt a service mesh (Istio, Linkerd, Cilium Service Mesh) to enforce mutual TLS between services, apply fine-grained authorization policies, and gain deep observability into service-to-service traffic without modifying application code.


Egress and External Connectivity

Egress Gateways

Controlling and auditing traffic leaving the cluster toward external systems is handled through egress rules in NetworkPolicy objects or, in more advanced setups, through dedicated egress gateways that provide a fixed, auditable source IP for outbound connections, which is often required for allow-listing on external firewalls.

NAT for Outbound Traffic

Because pod IPs are typically not routable outside the cluster, outbound traffic is usually masqueraded (SNAT) to the node's IP address before leaving the cluster network.


Multi-Cluster and Multi-Cloud Networking

Cluster Mesh

As organizations scale beyond a single cluster, technologies such as Cilium Cluster Mesh, Istio multi-cluster, or Submariner allow pods and services in different clusters, potentially across different clouds or regions, to discover and communicate with each other as if they were part of one larger network.

Considerations

These setups introduce additional concerns: overlapping pod CIDR ranges must be avoided, cross-cluster DNS resolution must be configured, and the latency and reliability of the interconnect between clusters becomes a first-class design factor.


Observability of Network Traffic

Metrics and Flow Logs

Understanding what is actually happening on the network is its own area of concern. eBPF-based tools can capture per-connection flow logs without requiring sidecars, while service meshes expose golden-signal metrics (latency, traffic, errors, saturation) for every service-to-service call.

Example: Connection Latency Relationship

The relationship between the number of hops a request traverses and the total observed latency can be expressed as a simple sum:

Ltotal = i=1 n Li

where each Li represents the latency contributed by hop i, such as a sidecar proxy, kube-proxy redirection, or an intermediate gateway.


Example NetworkPolicy

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend-to-backend
  namespace: production
spec:
  podSelector:
    matchLabels:
      app: backend
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: frontend
      ports:
        - protocol: TCP
          port: 8080

This policy restricts ingress traffic to pods labeled app: backend so that only pods labeled app: frontend may reach them on TCP port 8080, denying all other sources by default once any NetworkPolicy selects the pod.


Summary of Areas

Taken together, these areas form the full scope of what "Kubernetes networking" means in practice: the pod-level data plane (CNI), the service abstraction and load balancing layer (Services, kube-proxy or eBPF dataplanes), naming and discovery (DNS), external access (Ingress, Gateway API, LoadBalancer Services), security and segmentation (NetworkPolicy, service mesh), outbound control (egress gateways, NAT), cross-cluster connectivity, and the observability tooling needed to reason about all of the above.