CKAD Services and Networking Practice Question
A NetworkPolicy named 'deny-all' is applied in a namespace. Which YAML snippet correctly implements a default-deny-all ingress policy?
⚠ Common exam trap
The trap is that candidates often think specifying an empty `ingress: []` or `from: []` allows all traffic, but in Kubernetes NetworkPolicy, both an empty `ingress` list and an omitted `ingress` field result in denying all ingress traffic. However, the standard default-deny pattern is to omit the `ingress` field entirely while including `policyTypes: [Ingress]`.
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
✓
spec: podSelector: {} policyTypes: - Ingress
A NetworkPolicy with an empty `podSelector: {}` selects all pods in the namespace, and specifying `policyTypes: [Ingress]` without any `ingress` rules creates a default-deny-all ingress policy, blocking all incoming traffic. Options B and C include `ingress` rules (with empty `from`), which is not the standard approach for a strict deny-all; the canonical method is to omit the `ingress` field entirely when using `policyTypes: [Ingress]`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
spec: podSelector: {} policyTypes: - Ingress
Why this is correct
Empty podSelector targets all pods; no ingress rules means deny all ingress.
- ✗
spec: podSelector: {} ingress: - from: []
Why it's wrong here
An empty 'from' list actually allows all ingress because it matches nothing? Actually, an empty 'from' list allows no sources, but the presence of an ingress rule changes behavior. The standard default-deny uses no ingress rules.
- ✗
spec: podSelector: matchLabels: {} ingress: - from: []
Why it's wrong here
Same issue as C and B combined; empty matchLabels selects no pods.
- ✗
spec: podSelector: matchLabels: {} policyTypes: - Ingress
Why it's wrong here
matchLabels with empty map matches no pods; the policy doesn't apply.
Go deeper
Related to this question
About these practice questions
One of 160 original CKAD practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKAD 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 CKAD exam.