Skip to content

Network Policy: KCSA practice questions

A NetworkPolicy controls traffic at the IP address and port level (OSI layers 3 and 4) for TCP, UDP and SCTP, between Pods and between Pods and the outside world. It is an application-centric object in the networking.k8s.io API group.

By Ibrahim Yesilay · Published · Updated

Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.

What Network Policy covers in KCSA

A NetworkPolicy controls traffic at the IP address and port level (OSI layers 3 and 4) for TCP, UDP and SCTP, between Pods and between Pods and the outside world. It is an application-centric object in the networking.k8s.io API group. The peers a Pod may talk to are expressed in three ways: other Pods chosen by label, namespaces chosen by label, and IP blocks written as CIDR ranges. Labels are therefore the backbone of network segmentation; a policy can only target what it can select, which is why commands such as kubectl label pod matter here.

Without any policy, Pods are non-isolated: all inbound and all outbound connections are allowed. A Pod becomes isolated for ingress when at least one NetworkPolicy selects it and lists Ingress in its policyTypes, and isolated for egress when a selecting policy lists Egress. Once isolated in a direction, only connections explicitly allowed by some applicable policy are permitted, and reply traffic for those connections is allowed implicitly. Policies never conflict: they are additive, so the allowed set is the union of all applicable rules and evaluation order does not matter. For a connection between two Pods to succeed, the egress side of the source and the ingress side of the destination must both allow it.

The spec has a few fields to know precisely. podSelector chooses the Pods the policy applies to, and an empty podSelector selects every Pod in the namespace. policyTypes lists Ingress, Egress or both; if it is omitted, Ingress is always assumed and Egress is added only when the policy has egress rules. ingress rules use from, egress rules use to, and both combine peers with ports. Inside a peer, namespaceSelector alone admits all Pods in matching namespaces, while namespaceSelector and podSelector in the same element admit only matching Pods in matching namespaces, so YAML indentation changes the meaning. A default deny for egress is a policy with podSelector {} and policyTypes Egress and no egress rules; note that it also blocks DNS unless another policy allows traffic to the cluster DNS service. Leaving egress unrestricted means a compromised Pod can open connections to any destination.

Enforcement depends on the network plugin. Creating a NetworkPolicy in a cluster whose plugin does not implement it has no effect at all, which is the usual reason a policy seems to be ignored. The Kubernetes documentation lists Antrea, Calico, Cilium and Kube-router as providers. The API also has deliberate limits: it cannot handle TLS, cannot target Services by name, cannot log blocked connections and has no explicit deny rule. The documentation points to service meshes, ingress controllers and operating system components for those needs.

Key points

  • Pods are non-isolated by default: all ingress and egress is allowed until a policy selects them.
  • An empty podSelector ({}) selects every Pod in the policy’s namespace.
  • If policyTypes is omitted, Ingress is always set and Egress only when egress rules exist.
  • A NetworkPolicy has no effect unless the network plugin enforces it.

Three sample questions

18 KCSA questions on Network Policy, 18 with explanations. How practice works

Question 1

Which statement accurately describes how Kubernetes Network Policies control pod-to-pod communication within a cluster?
  1. A.By default, they block all traffic between pods.
  2. B.They use iptables rules (via the CNI plugin) to control pod communication.
  3. C.They are enforced by the kube-scheduler.
  4. D.They manage access to the Kubernetes API.
  5. E.They control storage access for pods.

Correct answer: B

Kubernetes Network Policies define how groups of pods are allowed to communicate with each other and with other network endpoints. These policies are enforced by the Container Network Interface (CNI) plugin used in the cluster. Most CNI plugins implement network policies using iptables or similar mechanisms to control traffic at the network level. By default, if no Network Policy is applied, all pods can communicate freely. Network Policies do not block all traffic by default, nor are they enforced by the kube-scheduler. They do not manage API or storage access.

Sources: Kubernetes Network Policies (Official Documentation), Kubernetes Security Best Practices (Mirantis)

Question 2

What is a common reason why a Kubernetes Network Policy might not be enforced as expected in a cluster?
  1. A.Network Policies are enabled by default in all clusters
  2. B.The installed CNI plugin does not support Network Policies
  3. C.The Network Policy YAML contains syntax errors
  4. D.The Kubernetes API server is unavailable
  5. E.Network Policies only apply to traffic from outside the cluster

Correct answer: B

Network Policies in Kubernetes rely on the underlying Container Network Interface (CNI) plugin to enforce rules. If the CNI plugin does not support Network Policies, then the policies will not be enforced regardless of their correctness. While syntax errors in the YAML or API server issues can cause problems, the primary reason Network Policies might not work is lack of CNI support. Also, Network Policies affect pod-to-pod traffic within the cluster, not just external traffic.

Sources: Kubernetes Official Documentation - Network Policies, CNI Plugins and Network Policy Support

Question 3

Which of the following are common CNI plugins that support Network Policies? (Select all that apply)

Select all that apply.

  1. A.Flannel
  2. B.Calico
  3. C.Weave Net
  4. D.AWS VPC CNI
  5. E.Cilium

Correct answers: B, C, D, E

Calico, Weave Net, Cilium, and AWS VPC CNI are CNI plugins that support Network Policies. AWS VPC CNI supports network policies but requires them to be enabled and does not support them for Fargate or Windows containers. Flannel does not support Network Policies by default.

Sources: AWS Announcement on VPC CNI Network Policy Support, AWS EKS Documentation on Network Policy Configuration, Kubernetes Documentation on Network Policies

Practice this topic

Focus mode keeps every question on Network Policy until you leave it. 10 free guest answers, then a free account; no credit card.

Or open KCSA practice across all topics.

Sources

The explanation above was checked against these official documents.

Frequently asked questions

Does a default-deny egress policy break DNS?

Yes. It blocks all egress from the selected Pods, including DNS lookups, so workloads that need name resolution need an additional policy that allows egress to the cluster DNS service.