CKAD · Question #13
Context: Set configuration context: [student@node-1] $ kubectl config use-context nk8s All work on this item should be conducted in the kdsn00201 namespace. All required NetworkPolicy resources are…
This question tests whether you understand how Kubernetes NetworkPolicies are applied to pods via label selectors, and that making a pod subject to an existing policy requires adding the correct labels to the pod - not modifying the policy itself.
Question
Explanation
This question tests whether you understand how Kubernetes NetworkPolicies are applied to pods via label selectors, and that making a pod subject to an existing policy requires adding the correct labels to the pod - not modifying the policy itself.
Approach. NetworkPolicies select the pods they govern using a podSelector that matches pod labels. Since the task explicitly forbids creating or modifying NetworkPolicies, the correct action is to inspect the existing NetworkPolicies in the kdsn00201 namespace (kubectl get networkpolicy -n kdsn00201 -o yaml) to find the policy whose podSelector targets pods allowed to communicate only with web and storage pods. Once you identify the required label(s) from that policy's podSelector, you apply those labels to kdsn00201-newpod using kubectl label pod kdsn00201-newpod -n kdsn00201 <key>=<value> or kubectl edit pod kdsn00201-newpod -n kdsn00201. This causes the existing NetworkPolicy to automatically select the pod, enforcing the desired traffic restriction without touching the policy resource itself.
Concept tested. Kubernetes NetworkPolicy pod selection via label matching - understanding that NetworkPolicies are applied to pods by matching podSelector labels on the pod, and that 'using' a policy means labeling the pod to match the policy's selector, not modifying the policy.
Reference. https://kubernetes.io/docs/concepts/services-networking/network-policies/#networkpolicy-resource
Topics
Community Discussion
No community discussion yet for this question.