- Four namespaces exist:
default,charms,potions, anddark-arts. defaultcontains one pod named Dumbledore with labelapp=Dumbledore.charms,dark-arts, andpotionseach contain three pods (names like Expecto Patronum, Imperio, Polyjuice) that have no labels.- No NetworkPolicies are present, so all pods can reach every other pod by default.
Why this is risky
- Any pod in
charmsorpotionscan communicate directly withdark-artspods — and vice versa. - A compromise in one department can spread laterally across the cluster unnoticed.
- Hogwarts requires department-level isolation so each namespace can only access what it needs.
Key NetworkPolicy features you’ll use
- Default-deny rules (deny-all ingress and/or egress).
- Explicit allow rules for specific pods and namespaces.
- Pod selectors, namespace selectors, or a combination (podSelector + namespaceSelector).
- Port restrictions (TCP/UDP and specific port numbers).
- IPBlock for egress to an IP range (e.g.,
10.0.0.0/24). - Policy types:
Ingress,Egress, or both.

Two hints from Hogwarts: use the labels that already exist, and remember that every namespace has a built-in label containing its name.
kubectl get networkpolicies --all-namespaces and test connectivity using kubectl exec or a network test pod.
Links and references
- Kubernetes NetworkPolicy documentation
- How NetworkPolicy selects pods
- IPBlock usage in NetworkPolicy