The cluster was dark, silent, and unreachable. Then the wrong pod started talking to the wrong service, and everything broke.
Kubernetes gives you power. Network Policies give you control. Without them, every pod in your cluster can talk to every other pod. That’s dangerous. With the right policies, you decide exactly which pods, namespaces, and IP ranges can connect. You can lock down ingress, egress, or both. You can make your cluster behave like a secure, segmented network instead of an open floor.
A Kubernetes NetworkPolicy is a resource that uses selectors to choose pods and define allowed traffic. You match labels. You set ingress rules to allow inbound traffic from specific sources. You set egress rules to limit outbound traffic. Traffic not explicitly allowed is denied. This is enforced at the network plugin level, so you need a CNI that supports it. Calico, Cilium, and Weave Net are popular choices.
A common first step is to deny all traffic into a namespace, then explicitly grant access only where needed. For example:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-by-default
namespace: secure-app
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
That’s the lockdown. Then you open doors one by one. If a frontend needs to talk to a backend, you label both pods and write a policy allowing that traffic.