Interview Prep/Networking/Kubernetes Networking

Isolate namespaces so only the frontend namespace can reach the backend namespace on port 8080.

IntermediateScenarioKubernetes Networking
Answer

Situation read → Needs a NetworkPolicy with namespace and pod selectors.

What I'd do →

  1. Label namespaces: kubectl label ns frontend team=frontend
  2. In the backend namespace create a policy: podSelector: matchLabels: app=api, ingress from namespaceSelector: matchLabels: team=frontend, port 8080
  3. Add a default-deny ingress policy
  4. Test with kubectl exec -n frontend deploy/web -- curl -m3 api.backend:8080 and from another namespace to confirm timeout

Why → Network policies are additive allow lists on top of a default deny.

Interview tip → Say namespaceSelector and podSelector in one from entry are ANDed, in separate entries ORed.

All Networking questions Roadmap: Networking for DevOps

More on Kubernetes Networking