Bitzu

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

Single choice

In a namespace with no NetworkPolicy objects, how is Pod traffic treated?

  1. All traffic is denied until a policy allows it
  2. Only traffic within the same namespace is allowed
  3. Only egress is allowed, ingress is denied
  4. 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.

Select all that apply

Which can be used inside a NetworkPolicy rule to say where allowed traffic may come from or go to?

  1. podSelector
  2. namespaceSelector
  3. serviceName
  4. nodeSelector
  5. 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

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.

Download on the App StoreGet it on Google Play

More KCNA topics in this module