Skip to main content
Bob is the new network security engineer for Hogwarts. The cluster he inherits runs several magical departments, each in its own Kubernetes namespace — but the cluster is wide open. There are no NetworkPolicies, so pods can talk to any other pod across all namespaces. This page explains the situation Bob finds, why it’s a problem, and the exact NetworkPolicy requirements Hogwarts gave him. Use this as a clear checklist when you write the seven policies: it covers names, labels, ports, namespace selectors, IPBlocks, and whether rules are ingress or egress. What Bob finds in the cluster
  • Four namespaces exist: default, charms, potions, and dark-arts.
  • default contains one pod named Dumbledore with label app=Dumbledore.
  • charms, dark-arts, and potions each 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.
Cluster summary Why this is risky
  • Any pod in charms or potions can communicate directly with dark-arts pods — 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.
Hogwarts’ exact requirements Hogwarts gave Bob a diagram and seven strict policies to implement. Every name, label, and port must match exactly — one typo can open or close a path incorrectly. We’ll walk through requirements namespace by namespace. 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.
An illustrated diagram titled "Everything Bob Has Learned" showing blue smiling pod icons connected by dashed arrows to represent network/Kubernetes policies. Labels include terms like charms, potions, hogwarts=admitted, class=potions, port numbers and the 10.0.0.0/24 subnet.
Two hints from Hogwarts: use the labels that already exist, and remember that every namespace has a built-in label containing its name.
Before you read the solution, try it yourself: seven NetworkPolicy manifests across four namespaces. If you implement them, verify with kubectl get networkpolicies --all-namespaces and test connectivity using kubectl exec or a network test pod. Links and references

Watch Video

Practice Lab