Network Policies and Segmentation
What You'll Learn
You'll learn how to implement container-level network policies that control traffic between pods and prevent attackers from moving laterally through your environment.
The Container Networking Challenge
By default, containers in orchestration platforms like Kubernetes can communicate freely with each other—like an office building where every door is unlocked. If an attacker compromises one container, they can potentially pivot to others, exfiltrate data, or establish persistence across your cluster. Network segmentation stops this lateral movement cold.
How Network Policies Work
Network policies act as virtual firewalls between containers (pods). Instead of allowing all-to-all communication, you define explicit rules that specify:
- Which pods can talk to each other (using labels like
app=frontend) - What protocols and ports are permitted (TCP port 443, for example)
- Direction of traffic (inbound/ingress or outbound/egress)
Think of it like airport security zones: passengers can't walk freely between terminals. They must pass through specific checkpoints with valid credentials.
Implementation Approach
In Kubernetes, you create NetworkPolicy resources that select pods using label selectors and define allowed connections. For instance, you might allow your frontend pods to reach backend pods on port 8080, but deny direct database access. You'd also block unexpected egress to prevent data exfiltration.
Policy enforcement requires a compatible Container Network Interface (CNI) plugin like Calico, Cilium, or Weave—the runtime components you've already learned about must support these rules.
Defense in Depth
Network policies complement the runtime isolation techniques you've studied (Seccomp, AppArmor, capabilities, user namespaces). Even if an attacker escapes a container constraint, network segmentation limits where they can go next.
Key Takeaway: Network policies create micro-perimeters around containers, enforcing least-privilege network access that blocks lateral movement and contains breaches at the pod level.