Question 662 of 997
Monitoring, Logging and Runtime SecuritymediumMultiple ChoiceObjective-mapped

Isolate a Compromised Pod Using NetworkPolicy

This CKS practice question tests your understanding of monitoring, logging and runtime security. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. A key principle to apply: networkPolicy. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

You need to isolate a compromised pod named 'malicious-pod' in the 'default' namespace so that it cannot communicate with any other pod, but can still receive traffic from a specific monitoring pod. Which NetworkPolicy should you apply?

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

apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: isolate-pod spec: podSelector: matchLabels: app: malicious-pod ingress: - from: - podSelector: matchLabels: app: monitoring-pod policyTypes: - Ingress - Egress

Option A is correct because it selects the compromised pod, allows ingress only from the monitoring pod (using podSelector), and specifies policyTypes as both Ingress and Egress. Since no egress rules are defined, egress traffic is denied by default, isolating the pod from initiating communication. Option B incorrectly allows all egress via an empty egress rule. Option C denies all ingress (no ingress rules) and thus blocks the monitoring pod. Option D allows all ingress and does not restrict egress, failing to isolate the pod.

Key principle: NetworkPolicy

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: isolate-pod spec: podSelector: matchLabels: app: malicious-pod ingress: - from: - podSelector: matchLabels: app: monitoring-pod policyTypes: - Ingress - Egress

    Why this is correct

    Allows ingress only from monitoring-pod, and blocks all egress by default. This isolates the pod while allowing monitoring.

    Related concept

    NetworkPolicy

  • apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: isolate-pod spec: podSelector: matchLabels: app: malicious-pod egress: - {} policyTypes: - Egress

    Why it's wrong here

    Allows all egress, which is not isolating the pod. Also does not restrict ingress.

  • apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: isolate-pod spec: podSelector: matchLabels: app: malicious-pod policyTypes: - Ingress - Egress

    Why it's wrong here

    This policy has no ingress or egress rules, so it denies all ingress and egress. The pod cannot receive any traffic, including from the monitoring pod.

  • apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: isolate-pod spec: podSelector: matchLabels: app: malicious-pod ingress: - {} policyTypes: - Ingress

    Why it's wrong here

    Empty ingress rule allows all inbound traffic, not just from monitoring-pod. Also does not restrict egress.

Common exam traps

Common exam trap: answer the scenario, not the keyword

A common mistake is thinking that an empty `ingress` or `egress` array denies all traffic, but in NetworkPolicy, if the policy type is specified and no rules are provided, all traffic of that direction is denied. However, if the policy type is not specified, traffic is allowed.

Detailed technical explanation

How to think about this question

Treat this as a scenario question. Identify the problem, the constraint, and the best action. Then compare each option against those facts.

KKey Concepts to Remember

  • NetworkPolicy
  • podSelector
  • ingress
  • egress
  • policyTypes

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

NetworkPolicy

Real-world example

How this comes up in practice

A practitioner preparing for the CKS exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. NetworkPolicy Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Review networkPolicy, then practise related CKS questions on the same topic to reinforce the concept.

Related practice questions

Related CKS practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free CKS practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this CKS question test?

Monitoring, Logging and Runtime Security — This question tests Monitoring, Logging and Runtime Security — NetworkPolicy.

What is the correct answer to this question?

The correct answer is: apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: isolate-pod spec: podSelector: matchLabels: app: malicious-pod ingress: - from: - podSelector: matchLabels: app: monitoring-pod policyTypes: - Ingress - Egress — Option A is correct because it selects the compromised pod, allows ingress only from the monitoring pod (using podSelector), and specifies policyTypes as both Ingress and Egress. Since no egress rules are defined, egress traffic is denied by default, isolating the pod from initiating communication. Option B incorrectly allows all egress via an empty egress rule. Option C denies all ingress (no ingress rules) and thus blocks the monitoring pod. Option D allows all ingress and does not restrict egress, failing to isolate the pod.

What should I do if I get this CKS question wrong?

Review networkPolicy, then practise related CKS questions on the same topic to reinforce the concept.

What is the key concept behind this question?

NetworkPolicy

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

5 more ways this is tested on CKS

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. An incident responder needs to isolate a compromised pod immediately without deleting it. Which action should they take?

hard
  • A.Modify the pod's labels to prevent it from receiving traffic
  • B.Delete the pod to stop its activity
  • C.Apply a NetworkPolicy that denies all traffic to and from the pod's labels
  • D.Scale down the deployment to zero replicas

Why C: Applying a NetworkPolicy that denies all ingress and egress traffic to the pod isolates it from network communication while preserving the pod for forensic analysis. Option A (modifying labels) may not be sufficient to stop traffic. Option B (deleting the pod) removes evidence. Option D (scaling down) is not immediate and may delete the pod.

Variation 2. Which THREE of the following are valid techniques for isolating a compromised pod during incident response? (Choose three)

hard
  • A.Modify the container image to disable networking
  • B.Apply a NetworkPolicy that denies all ingress and egress traffic to the pod
  • C.Cordon the node where the pod is running
  • D.Add a label 'isolated=true' to the pod and apply a NetworkPolicy that selects that label and denies all traffic
  • E.Delete the pod immediately to stop the threat

Why B: Option B is correct because applying a NetworkPolicy that denies all ingress and egress traffic to the pod effectively isolates it at the network layer, preventing any lateral movement or data exfiltration. This is a standard incident response technique that uses Kubernetes-native network policy rules to create a network-level quarantine without modifying the pod or its image.

Variation 3. During a security incident, you need to isolate a compromised pod named 'malicious-pod' in namespace 'default' to prevent it from communicating with other pods. Which command should you run?

hard
  • A.kubectl run networkpolicy --image=nginx --restart=Never
  • B.kubectl delete pod malicious-pod
  • C.kubectl apply -f networkpolicy.yaml
  • D.kubectl create networkpolicy isolate --pod-selector=app=malicious --policy-types=Ingress,Egress

Why C: Pod isolation is achieved by applying a NetworkPolicy that denies ingress/egress traffic. 'kubectl apply -f networkpolicy.yaml' applies the policy. The policy must be written to deny all traffic.

Variation 4. Which THREE of the following are recommended steps when responding to a compromised pod?

hard
  • A.Immediately delete the pod to stop the attack
  • B.Scale the deployment replicas to zero to stop the pod
  • C.Run kubectl exec to investigate the container's state
  • D.Isolate the pod using a NetworkPolicy that denies all egress
  • E.Capture a snapshot of the container's filesystem using kubectl cp

Why B: Isolating the pod via NetworkPolicy, capturing a forensic snapshot (e.g., using kubectl cp), and scaling replicas to zero are all valid steps. Deleting the pod immediately may destroy evidence. Running commands inside the pod could alter state.

Variation 5. To isolate a compromised pod and prevent all incoming and outgoing traffic, which Kubernetes resource should you use?

easy
  • A.ResourceQuota
  • B.PodSecurityPolicy
  • C.NetworkPolicy with spec.podSelector: {} and spec.policyTypes: [Ingress, Egress]
  • D.LimitRange

Why C: A NetworkPolicy with `spec.podSelector: {}` selects all pods in the namespace, and `spec.policyTypes: [Ingress, Egress]` with no rules under `ingress` or `egress` defaults to denying all traffic. This effectively isolates the compromised pod by blocking all incoming and outgoing network traffic at the CNI level.

Keep practising

More CKS practice questions

Last reviewed: Jun 21, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.