KCNA ยท Kubernetes networking
NetworkPolicy basics
Default allow behaviour, selecting Pods, ingress/egress rules, CNI enforcement requirement.
Key points
- By default Pods accept and send any traffic.
- A NetworkPolicy selects Pods with podSelector and, for the directions listed in policyTypes (Ingress, Egress), makes those Pods isolated so only traffic allowed by some policy gets through.
- Policies are additive allow rules, and they are enforced by the CNI plugin: without a plugin that supports them, the objects have no effect.
Source: https://kubernetes.io/docs/concepts/services-networking/network-policies/
Practice questions
In a namespace with no NetworkPolicy objects, how is Pod traffic treated?
- All traffic is denied until a policy allows it
- Only traffic within the same namespace is allowed
- Only egress is allowed, ingress is denied
- All ingress and egress traffic is allowed
Show answer
Answer: D. All ingress and egress traffic is allowed
Pods are non-isolated by default, so all ingress and egress is allowed. Restrictions begin only once a policy selects a Pod.
Which can be used inside a NetworkPolicy rule to say where allowed traffic may come from or go to?
- podSelector
- namespaceSelector
- serviceName
- nodeSelector
- dnsName
Show answer
Answer: A. podSelector, B. namespaceSelector
Rules can reference Pods (podSelector), namespaces (namespaceSelector) and CIDR ranges (ipBlock). Service names and node labels are not rule peers.
True or false: If two NetworkPolicies select the same Pod, a deny in one overrides an allow in the other.
Show answer
Answer: False
False. Policies only add allowances, never conflict, and the allowed traffic is the union of all rules that apply.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
