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 →
- Label namespaces:
kubectl label ns frontend team=frontend - In the backend namespace create a policy:
podSelector: matchLabels: app=api, ingress fromnamespaceSelector: matchLabels: team=frontend, port 8080 - Add a default-deny ingress policy
- Test with
kubectl exec -n frontend deploy/web -- curl -m3 api.backend:8080and 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.
More on Kubernetes Networking
Explain the Kubernetes networking model in one minute.BeginnerClusterIP, NodePort and LoadBalancer: when do you use each?BeginnerHow does a pod find another service by name?BeginnerService versus Ingress: what is the difference?BeginnerWhat does a CNI plugin do and which ones do you know?BeginnerHow do you reach a pod from your laptop for debugging without exposing it?Beginner