CKS · Question #71
You must connect to the correct host. Failure to do so may result in a zero score. Context You must implement NetworkPolicies controlling the traffic flow of existing Deployments across namespaces…
This question tests the ability to create Kubernetes NetworkPolicy objects to control ingress traffic between namespaces - a core CKA task involving namespace isolation and cross-namespace traffic rules.
Question
Exhibit
Explanation
This question tests the ability to create Kubernetes NetworkPolicy objects to control ingress traffic between namespaces - a core CKA task involving namespace isolation and cross-namespace traffic rules.
Approach. Create 'deny-policy' in the prod namespace with an empty podSelector (selects all pods) and policyTypes: [Ingress] with no ingress rules - this denies all inbound traffic to every pod in prod. Then create 'allow-from-prod' in the data namespace with an empty podSelector and an ingress rule using a namespaceSelector matching the label env: prod - this allows only pods from the prod namespace to send traffic into data. The critical detail is using namespaceSelector with matchLabels: {env: prod} (the namespace label, not a pod label) in the allow-from-prod policy. Both policies use podSelector: {} to target all pods in their respective namespaces.
Concept tested. Kubernetes NetworkPolicy - default-deny ingress patterns, namespaceSelector-based ingress rules, and the distinction between podSelector (targets pods within the policy's namespace) vs. namespaceSelector (restricts source namespace by label)
Reference. https://kubernetes.io/docs/concepts/services-networking/network-policies/
Topics
Community Discussion
No community discussion yet for this question.
