Lock down a namespace with NetworkPolicies

  • 12 min
  • 6 steps
  • Networking

Steps

0 of 6 done

Isolate every pod in shop, restore DNS, then open exactly the paths the frontend and one debug pod need.

  1. Step 1 of 6

    No policy exists yet. From the debug pod in the tools namespace, fetch the front page of the api Service in shop to see that traffic between namespaces is open by default.

    Checked against what your commands print.

  2. Step 2, not started: Isolate every pod in shop for both ingress and egress, using the policy file in the working directory written for that.

  3. Step 3, not started: frontend can no longer resolve any name, because its egress to CoreDNS is dropped. Two drafts of a DNS policy are in the working directory and only one of them selects the CoreDNS pods on this cluster. Find out which, and apply it.

  4. Step 4, not started: Let frontend reach api over HTTP again without opening anything else. frontend and api are both isolated, so think about which side of the connection each remaining file permits.

  5. Step 5, not started: The debug pod in tools carries the label app=frontend as well, yet its request to api times out. Ask the API server how it reads api-allow-frontend and find which pods its from peer can match.

  6. Step 6, not started: Allow pods labelled app=frontend in the tools namespace, and nowhere else, to reach api. Do not change the policies you have already applied.

Lab terminal

Cluster time 50 seconds
kind cluster kx, Kubernetes 1.37.
Each step is checked as you work.
​
Tab completes. Up and Down recall.
Type help for more.
Terminal keys

Enter runs the command. Tab completes, and the arrow keys recall earlier commands. Control C stops a watch. On an empty line, or after Escape, Tab moves focus out of the terminal.