How to Read a NetworkPolicy · CKA
Read traffic permissions by separating direction, peers, and ports.
Learn with progress and quizzesFirst, understand the concepts.
Isolation and allowance
When a policy selects a Pod for ingress or egress, that direction becomes isolated. Allowed traffic across multiple policies is combined as a union.
Implementation requirement
Your network plugin must support NetworkPolicy. Creating a policy object alone does not guarantee that traffic is blocked on every cluster.
Why it matters
Before reading allowed peers, identify which Pods and traffic directions are isolated. Client egress and server ingress are separate checks.
Work through the reasoning
Separate subjects from peers
The top-level podSelector chooses the Pods governed by the policy. from and to choose peers. namespaceSelector and podSelector within one peer must both match; separate peer entries add alternatives.
Connect both directions
If both client egress and server ingress are isolated, both must allow the connection. Permissions from multiple policies combine. DNS is also egress, so allowing an application port alone may not enable name resolution.
Learn by doing.
You need kubectl and access to your own practice Kubernetes cluster. Each lab is independent. Check your current context first, then run the commands in your own terminal.
Inspect the current policies and schema, then explain ingress and egress directions. This exercise does not change policies.
kubectl get networkpolicies -A
kubectl explain networkpolicy.spec
kubectl explain networkpolicy.spec.ingress
kubectl explain networkpolicy.spec.egressHow to check your result
Distinguish podSelector, which identifies the target Pods, from ingress.from, which identifies permitted incoming sources.
Apply what you learned
Server ingress allows the client, but the client has deny-all egress. Will the request connect?
Reveal the reasoning after trying
Not unless another policy allows that client’s egress. Define the needed destination and port, account for DNS when using names, and test each direction separately.
Ready to check your understanding?
If two policies allow traffic to the same Pod, how are their permissions combined?
- Only the last policy applies
- The union of allowed traffic
- All traffic is blocked
- Only the first policy applies
Reveal the reasoning after trying
The union of allowed traffic
Allow rules are additive. A connection must also satisfy any applicable source egress and destination ingress policies.