Without a policy, every Pod can reach every other By default Kubernetes allows all Pod-to-Pod traffic. Even the debug Pod in another namespace (ops) can connect straight to db.
A namespace is a boundary for names and permissions, not for traffic. Blocking traffic takes a NetworkPolicy.
Apply a default-deny policy to the whole namespace The admin creates a default-deny policy. An empty Pod selector means "every Pod in shop", and it blocks both incoming (Ingress) and outgoing (Egress) traffic.
Policies have no "deny" rules. Pods selected by a policy switch to allow-list mode, where only listed traffic passes, and the list starts empty.
Key idea The safe order is: apply default deny first, then open each needed path with an allow policy.
Cilium is what actually enforces the policy A policy is just a rule document. Traffic is only blocked when the network plugin (CNI) watches policies and filters packets on each node. This lesson assumes Cilium does that job.
Cilium inspects Pod traffic with small programs loaded into the Linux kernel (eBPF).
Key idea With a network plugin that does not support policies, creating one has no effect and raises no error.
Traffic that used to work now times out When frontend calls backend, no response comes back. Cilium silently drops the packets, so the caller waits until its timeout instead of getting a "refused".
Because egress is blocked too, DNS lookups (port 53) fail as well and "name not found" errors appear. That is why an allow-dns policy usually goes alongside.
Watch out The moment you first apply a policy, traffic that used to work can break. Before applying, make sure you know that anything not in the rules will be blocked.
Open only frontend → backend, by label Allow traffic into backend from "Pods labelled app=frontend". Since default deny also blocks egress, open frontend’s outgoing path to backend as well.
Selection is by label, not Pod name, so a newly started frontend Pod with the same label is allowed automatically.
What changed in this step
+ allow-frontend (backend Ingress)+ frontend Egress → backenddb only accepts port 5432 from backend Add a policy on the db Pod that "only allows port 5432 traffic from app=backend". Open backend’s outgoing path to db too.
When several policies select one Pod, the allowed traffic is the union of what each policy allows.
What changed in this step
+ db-allow-backend (db Ingress :5432)+ backend Egress → dbRequests outside the allow list just hang When the debug Pod and frontend try to reach db, both wait with no answer and fail on timeout. Only backend is on db’s allow list.
To the app this easily looks like "the server is slow" or "down". The db Pod is Running and the Service is fine, which makes the cause hard to find.
Watch out NetworkPolicy filters at the IP and port level (L4). Blocking specific URL paths is a job for a service mesh or gateway.
Blocked traffic is not recorded on the policy A NetworkPolicy object only holds rules; it does not record which traffic was actually blocked. To see drops, use a CNI tool such as Cilium’s Hubble.
When traffic breaks, use kubectl describe networkpolicy to see what is allowed for Ingress and Egress, and compare the policy’s Pod selector with the target Pod’s labels side by side.
Block first, then open only the paths you need by label No policy means allow-all; once selected by a policy, a Pod uses an allow list. We applied default deny, then opened only frontend → backend → db by label.
The policy is the document; Cilium does the enforcing. Blocked requests show up as timeouts, not errors.
Summary NetworkPolicy opens labelled paths on top of a default deny. Before applying a policy, check which Pods its selector matches with kubectl get pods -l.