Course contentsShow
← Cloud and Infrastructure
Lesson 1234 of 2,98924. Kubernetes NetworkingFree lesson

NetworkPolicy Fundamentals

Understand Kubernetes NetworkPolicies, their purpose for pod-to-pod traffic control, and default allow-all behavior.

NetworkPolicy Fundamentals

What you'll learn: How Kubernetes NetworkPolicies control pod-to-pod traffic and why the default network behavior is open.

What is a NetworkPolicy?

A NetworkPolicy is a Kubernetes resource that acts like a firewall for your pods. It defines rules about which pods can communicate with each other and what external endpoints they can reach. Think of it like security gates in an office building—without them, anyone can walk into any room, but with them, you control who goes where.

Default Network Behavior: Allow All

By default, Kubernetes operates in an "allow-all" mode. Every pod can talk to every other pod in the cluster, regardless of namespace or label. While this makes getting started easy, it's not secure for production environments where you want to isolate workloads.

Once you create your first NetworkPolicy that selects a pod, that pod switches from "allow-all" to "deny-all" mode—only the traffic you explicitly permit will be allowed.

Why NetworkPolicies Matter

Without NetworkPolicies:

  • A compromised frontend pod could access your database directly
  • Pods in different namespaces can freely communicate
  • You have no network segmentation or zero-trust architecture

With NetworkPolicies:

  • Control ingress (incoming) traffic to pods
  • Control egress (outgoing) traffic from pods
  • Enforce principle of least privilege at the network layer
  • Create namespace isolation and micro-segmentation

Network Plugin Requirement

NetworkPolicies are just specifications—your cluster needs a network plugin (CNI) that enforces them, such as Calico, Cilium, or Weave Net. The standard Kubernetes networking without a policy-aware CNI will ignore NetworkPolicy resources.

Key Takeaway: NetworkPolicies are Kubernetes firewall rules that control pod-to-pod traffic; clusters default to allowing all traffic until you define your first policy, at which point selected pods switch to deny-all mode.