The first pod dropped, and traffic moved freely—too freely. Within seconds, every service could talk to every other. That’s default Kubernetes networking. Powerful, but dangerous.
Kubernetes Network Policies give you control. They define which pods can talk and on which ports. Without them, an internal compromise can spread fast. With them, you reduce the blast radius and enforce least privilege communication.
A Network Policy is a Kubernetes resource. It uses namespace and label selectors to match pods, and it defines ingress and egress rules. By default, Kubernetes allows all traffic between pods. Once any Network Policy selects a pod, traffic is denied unless explicitly allowed. This makes the first policy you apply an important proof of concept.
To create a Kubernetes Network Policies proof of concept, follow a minimal path:
- Choose a namespace for testing.
- Deploy two pods—one as the “secure” service, one as a “client.” Label them clearly.
- Confirm connectivity with
kubectl execand curl or nc. - Write a NetworkPolicy manifest that allows only traffic from the client pod label to the secure pod label over a chosen port.
- Apply the policy and retest connectivity.
- Observe the block by trying to connect from a pod without the allowed label.
YAML example: