What is the purpose of a NetworkPolicy in Kubernetes?
- Manage service discovery
- Set resource quotas per pod
- Configure DNS resolution
- Define firewall rules for pod traffic ✓
Correct answer: Define firewall rules for pod traffic
Option D is correct because a Kubernetes NetworkPolicy is a namespace-scoped resource that uses label selectors to define ingress and egress firewall rules controlling which pods can communicate with each other and with external endpoints, enforced by the cluster's CNI plugin. Option A is incorrect because service discovery in Kubernetes is handled by the DNS service (CoreDNS) and the Service resource, not by NetworkPolicy. Option B is incorrect because resource quotas per pod are managed by LimitRange and ResourceQuota objects, not NetworkPolicy. Option C is incorrect because DNS resolution configuration is the responsibility of CoreDNS ConfigMaps and the dnsPolicy field on pod specs, not NetworkPolicy.
Topic: · networkpolicy, kubernetes networking, pod security, cni