π§ CKAD NetworkPolicy Exam Strategy & Labeling Guide¶
Goal: Identify which pod is protected, which pods send traffic, which pods receive traffic β and apply correct labels based on the NetworkPolicy YAML.
π©΅ Step 1 β Read the Question Carefully¶
- The first pod name in the question = your protected pod.
- Thatβs the one the NetworkPolicy applies to (the βroom with the doorβ).
Example
Pod
backendshould only receive traffic fromfrontendand send traffic todatabase.
β
Protected Pod: backend β
It receives (Ingress) from frontend β
It sends (Egress) to database
π©΅ Step 2 β Find the Correct NetworkPolicy¶
kubectl get netpol -n <namespace>
kubectl describe netpol <name> -n <namespace>
Look for:
spec:
podSelector:
matchLabels:
key=value
This shows which pod the policy applies to.
If that pod doesnβt already have the label β add it:
kubectl label pod <protected-pod> key=value -n <namespace>
π©΅ Step 3 β Understand the Policy Sections¶
| Section | Meaning | Traffic Direction |
|---|---|---|
podSelector | The protected pod | β |
ingress.from | Who can talk to me | Incoming |
egress.to | Who I can talk to | Outgoing |
π©΅ Step 4 β Decide Labels Using Question Context¶
| Question phrase | Direction | Apply label from | To which pod |
|---|---|---|---|
| βshould receive traffic from β¦β | Ingress | ingress.from | Sender pod(s) |
| βshould send traffic to β¦β | Egress | egress.to | Receiver pod(s) |
| βshould communicate only with β¦β | Both | ingress.from + egress.to | Both sender + receiver |
π©΅ Step 5 β Label Pods Accordingly¶
Example policy:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: backend-policy
spec:
podSelector:
matchLabels:
tier: backend
ingress:
- from:
- podSelector:
matchLabels:
tier: frontend
egress:
- to:
- podSelector:
matchLabels:
tier: database
Labeling Commands:
kubectl label pod frontend tier=frontend -n ckad-netpol
kubectl label pod backend tier=backend -n ckad-netpol
kubectl label pod database tier=database -n ckad-netpol
β
backend = protected β
frontend = sender (from) β
database = receiver (to)
π©΅ Step 6 β Verify Labels and Policies¶
kubectl get pods -n ckad-netpol --show-labels
kubectl describe netpol backend-policy -n ckad-netpol
(Optional)
kubectl exec -it frontend -- curl backend:80
π©΅ Step 7 β Default-Deny Awareness¶
If this exists:
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
Then all traffic is denied by default β only explicitly allowed NetworkPolicies will work.
π©΅ Step 8 β Mental Model¶
frontend ---> backend ---> database
| | |
from podSelector to
(sender) (protected pod) (receiver)
β βfromβ = sender β ingress β βtoβ = receiver β egress
π©΅ Step 9 β Exam Shortcut¶
π§© Who the question starts with β protected pod π§© Who it receives from β ingress.from (sender) π§© Who it sends to β egress.to (receiver)
π©΅ Step 10 β Quick Command Template¶
# Identify all policies in namespace
kubectl get netpol -n <ns>
# View the right one
kubectl describe netpol <name> -n <ns>
# Label pods
kubectl label pod <protected> <key=value> -n <ns>
kubectl label pod <sender> <key=value> -n <ns>
kubectl label pod <receiver> <key=value> -n <ns>
# Confirm
kubectl get pods -n <ns> --show-labels
πͺ Memory Tip¶
π§ Think in human language:
- βI am the protected room.β β
podSelector - βThese people can knock on my door.β β
ingress.from - βThese are the rooms Iβm allowed to visit.β β
egress.to