CKS Minimize Microservice Vulnerabilities Practice Question
You need to create a NetworkPolicy that denies all ingress traffic to pods with label 'app: web' in the 'frontend' namespace, except for traffic from pods with label 'app: ingress' in the 'ingress' namespace. Which NetworkPolicy spec correctly achieves this?
⚠ Common exam trap
A common trap in CKS is to confuse AND vs OR logic in NetworkPolicy selectors. Option C uses separate 'from' entries (OR logic), making it overly permissive, while the correct approach combines namespaceSelector and podSelector in a single 'from' block (AND logic).
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: ingress podSelector: matchLabels: app: ingress
It uses a single `from` entry with both a `namespaceSelector` (matching the `ingress` namespace by its `kubernetes.io/metadata.name` label) and a `podSelector` (matching pods with `app: ingress`). This combination restricts ingress traffic to only pods that are both in the `ingress` namespace AND have the label `app: ingress`, while implicitly denying all other ingress traffic to pods labeled `app: web` in the `frontend` namespace.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
ingress: - from: - namespaceSelector: matchLabels: name: ingress podSelector: matchLabels: app: ingress
Why it's wrong here
This rule incorrectly assumes the namespace in question carries a label with the key 'name' and value 'ingress'. Kubernetes automatically labels namespaces with 'kubernetes.io/metadata.name' (whose value is the namespace name), not 'name' — unless an operator manually applied such a label, this selector will match no namespaces, making the rule ineffective. Even though the same 'from' entry correctly ANDs the namespace and pod selectors, the namespace selector itself is broken.
- ✗
ingress: - from: - namespaceSelector: matchLabels: app: ingress podSelector: {}
Why it's wrong here
Here the empty podSelector (i.e., 'podSelector: {}') selects all pods in any namespace that carries the label 'app: ingress', not only pods with that label in the specific ingress namespace. This broadens the allowed sources to every pod in every namespace that happens to be labeled 'app: ingress', including potentially unrelated workloads. The rule fails to pin down both the namespace and the pod identity simultaneously, so it permits far more ingress than intended.
- ✗
ingress: - from: - podSelector: matchLabels: app: ingress - namespaceSelector: matchLabels: kubernetes.io/metadata.name: ingress
Why it's wrong here
This policy splits the desired condition into two separate 'from' entries: one that selects any pod with app: ingress in any namespace, and another that selects any pod in the namespace labeled 'kubernetes.io/metadata.name: ingress'. Because entries in the 'from' list are OR'd together, traffic is allowed from either source — meaning any matching pod outside the ingress namespace or any pod inside that namespace (even without the app label) can reach the protected service. The correct approach requires both selectors within a single 'from' entry so they are ANDed.
- ✓
ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: ingress podSelector: matchLabels: app: ingress
Why this is correct
This is correct because a single 'from' entry containing both a namespaceSelector and a podSelector applies Boolean AND semantics: the source pod must run in a namespace that carries the 'kubernetes.io/metadata.name: ingress' label (i.e., the namespace literally named 'ingress') AND the pod itself must have the label 'app: ingress'. Since no other ingress rules exist, the policy defaults to deny all other ingress traffic, precisely matching the requirement. Using the standard metadata.name label ensures reliable namespace identification without relying on manually maintained labels.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CKS question from scratch — 845 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKS practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKS exam.