Pod networking, CNI, MTU, and NetworkPolicy semantics

Flat pod network unless a policy says otherwise, and the first policy you apply usually breaks DNS. Overlays cost MTU; routed CNIs cost IP space.

Read the briefing
About 4 min to read 7 drills

What to remember

  1. Selecting a pod in any policy makes it default-deny. Always allow kube-dns egress in the same change, or you have broken name resolution.
  2. Policies are allow-lists that union — no deny exists. 'Still reachable' means another policy permits it.
  3. Overlay encapsulation eats 50-80 bytes of MTU. Large responses hanging while small ones pass is the signature.
  4. Routed CNIs make pod IPs a capacity planning problem. VPC-native clusters run out of addresses, not CPU.
  5. Roll default-deny out namespace by namespace. With a template that always permits DNS and monitoring, in audit mode first where the CNI supports it.

The big picture

Kubernetes promises a flat network: every pod gets its own IP, every pod can reach every other pod without NAT, and nodes can reach pods. The CNI plugin is what makes that promise true on your infrastructure, and NetworkPolicy is how you take some of it back. Interviewers test whether you understand the model well enough to debug "pods cannot talk" and to design isolation that does not break DNS.

The mental model

Three layers. The model (pod-per-IP, no NAT) is a contract. The CNI plugin implements it either by encapsulating pod traffic in an overlay (VXLAN/Geneve) or by routing pod CIDRs natively (BGP, cloud routes, VPC-native IPs). NetworkPolicy is an allow-list evaluated per pod: once any policy selects a pod, everything not explicitly allowed in that direction is denied, and policies add up, they never subtract.

In depth

The model and how CNIs deliver it

The kubelet asks the CNI plugin to set up networking when a pod's sandbox is created: create a veth pair, assign an IP from the node's pod CIDR (or the VPC), install routes. Overlay CNIs (Flannel VXLAN, Calico with IPIP/VXLAN, Cilium with tunnelling) encapsulate pod packets inside node-to-node packets, which works on any network but costs MTU and CPU. Routed CNIs (Calico BGP, Cilium native routing, AWS VPC CNI, GKE VPC-native) make pod IPs routable on the underlying network: better performance and observability, tighter coupling to the cloud (IP exhaustion, route table limits). kube-proxy (or the CNI's eBPF replacement) is separate: it implements Services, not pod connectivity.

Debugging connectivity: is the pod IP assigned (kubectl get pod -o wide)? Can the node reach the pod? Can a pod on another node reach it (kubectl exec … -- nc -zv <ip> <port>)? If cross-node fails and same-node works, suspect the overlay or routes (cloud security groups blocking the VXLAN port, 4789 or Flannel's 8472, or missing routes). If everything works except large payloads, suspect MTU.

MTU: the silent killer

Encapsulation adds bytes: VXLAN adds 50, so a 1500-byte underlay leaves 1450 for the pod. If the pod interface advertises 1500, large packets are fragmented or dropped; the symptom is that small requests succeed and large ones hang (TLS handshakes complete, big responses stall). Path MTU discovery often fails because ICMP is filtered. Fixes: set the CNI's MTU to underlay minus overhead, enable jumbo frames on the underlay if the cloud supports it, or use a routed CNI without encapsulation. ip link show inside a pod and ping -M do -s 1400 are the diagnostic tools.

NetworkPolicy semantics

A NetworkPolicy has a podSelector, policyTypes (Ingress, Egress, or both), and rules. Isolation is per direction: a pod selected by any policy with policyTypes: [Ingress] denies all ingress not allowed by some policy; the same for Egress. Policies are additive: multiple policies selecting a pod union their allows. An empty podSelector: {} selects every pod in the namespace, which is how you write a default-deny. from/to entries can be podSelector, namespaceSelector (match on namespace labels, including the automatic kubernetes.io/metadata.name), ipBlock, or a combination in one entry (AND) versus separate entries (OR).

The classic mistake: a default-deny egress policy that forgets DNS. Every pod resolves names through CoreDNS (kube-system, UDP and TCP 53), so egress policies must allow it or everything "breaks randomly". Policies are enforced by the CNI; a cluster whose CNI does not support NetworkPolicy accepts the objects and enforces nothing, which is worse than no policy.

Myths and facts

Myth: NetworkPolicies are deny rules; I add one to block traffic.

Fact: They are allow-lists. Selecting a pod isolates it; rules then allow specific traffic. There is no deny rule.

Myth: If two policies conflict, the more specific one wins.

Fact: Policies never conflict; they union. Anything allowed by any policy is allowed.

Myth: A NetworkPolicy in namespace A can restrict pods in namespace B.

Fact: A policy only selects pods in its own namespace; it can allow traffic from or to other namespaces.

Myth: The cluster accepted my NetworkPolicy, so it is enforced.

Fact: Enforcement requires a CNI that implements NetworkPolicy; otherwise the object is inert.

Myth: Pods talk to Services, so policies should target Service IPs.

Fact: Policies operate on pod selectors and IPs after Service translation; target the backend pods' labels.

How pros do it

  • Start every production namespace with a default-deny ingress policy plus an egress policy that allows DNS to kube-system.
  • Allow traffic by label selectors, not IP blocks, so policies survive pod churn.
  • Verify enforcement after writing a policy: test from a pod that should be blocked, not only from one that should work.
  • Set the CNI MTU deliberately for overlays; alert on interface drops and fragmentation.
  • Prefer a CNI with flow visibility (Cilium Hubble, Calico flow logs) so 'who is talking to whom' is answerable.

Questions people ask

I added a default-deny policy and now nothing resolves DNS. Why?

Egress isolation blocked port 53 to CoreDNS. Add an egress rule allowing UDP and TCP 53 to pods labelled k8s-app: kube-dns in kube-system (a namespaceSelector on kubernetes.io/metadata.name: kube-system ANDed with the podSelector in one entry), and ship it in the same commit as every default-deny from now on.

Pods can reach each other on the same node but not across nodes. What is it?

Almost always the underlay: security groups or firewalls blocking the overlay port (VXLAN UDP 4789, or 8472 for Flannel and Cilium; Geneve 6081; IPIP), or missing routes for pod CIDRs in a routed setup. Same-node traffic never leaves the host, which is the bisection.

Everything works except large responses hang. Why?

MTU. The overlay's overhead exceeds the underlay MTU, full-size packets are dropped, and the ICMP that path-MTU discovery needs rarely gets back across the overlay. Say 'small works, large hangs, MTU' before anything else; the fix is the CNI MTU set to underlay minus overhead (1450 for VXLAN on 1500), or jumbo frames on the underlay.

How do I allow only namespace X to call my service?

An ingress rule with a namespaceSelector matching X's labels (for example kubernetes.io/metadata.name: x), optionally ANDed with a podSelector for the caller pods in the same entry; two separate entries would be an OR. Then test from a pod that should be blocked, not only from one that should work.

Can NetworkPolicy block traffic from outside the cluster?

Only for traffic that arrives with its source IP intact, via ipBlock ranges. Traffic through a load balancer that SNATs looks like the node, so combine it with LB-level controls or externalTrafficPolicy Local.

Further reading

Drills · 7

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Find what's broken

You apply this and the api pods now fail every request with could not resolve host: postgres.shop.svc; the team insists 'the policy allows Postgres'. Which line is the bug, and which line is a second, quieter problem?

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-lockdown
  namespace: shop
spec:
  podSelector:
    matchLabels:
      app: api
  policyTypes: [Ingress, Egress]
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: ingress-nginx
      ports:
        - port: 8080
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: postgres
      ports:
        - port: 5432
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except: [10.0.0.0/8]
      ports:
        - port: 443
In short

The egress block (line 18) forgets to allow DNS to kube-dns, and the 0.0.0.0/0 rule on 443 (line 26) opens the whole internet.

What's broken
  • Line 18: Egress isolation is on, but the egress block has no rule allowing DNS (UDP/TCP 53) to CoreDNS in kube-system, so every name lookup is dropped before the Postgres rule can matter.
  • Line 26: Allowing 0.0.0.0/0 on 443 with only the private range excepted lets the pod reach any public host, including the cloud metadata service if it is not in the except list on that platform; broad egress defeats the lockdown.
Why

DNS is the egress rule everyone forgets: with Egress in policyTypes, resolution is denied unless explicitly allowed, and the failure looks like 'the policy is not working'. The broad 443 rule is the second-order problem: a lockdown that permits the whole internet is not one.

The common mistake

Blaming CoreDNS or saying 'the policy is not working'. The policy is working exactly as written: resolution is denied before the Postgres rule can matter.

Read the docs

2 Answer out loud

Explain the Kubernetes network model to me. What is the difference between an overlay and a routed CNI — one consequence each — and what are the two rules for how NetworkPolicies combine? Four to six sentences.

In short

A strong answer states pod-per-IP with no NAT, one cost for overlay and one for routed, and the two rules: selection isolates and rules only allow.

What a strong answer does
  • model and cni: Contract stated; overlay costs MTU/CPU and works anywhere; routed performs better but depends on cloud routing/IP capacity; kube-proxy is separate.
  • policy semantics: Per-direction isolation on selection, additive union across policies, AND within a from/to entry vs OR across entries, DNS as the standard exception.
  • communication: Model, CNI contrast, two policy rules, each crisp.
Why

Interviewers listen for the contract, one honest tradeoff per CNI style, and the two semantic rules stated precisely.

The common mistake

Describing NetworkPolicies as deny rules with precedence. There is no deny and no ordering; anything any policy allows is allowed, and the first policy that selects a pod is what switches that direction to default-deny.

3 Pick the strongest answer

'Here is a NetworkPolicy — what does it actually do?' It has podSelector: {app: api}, policyTypes: [Ingress], and one rule allowing ingress from pods labelled app: web. What is the effect on the api pods?

  1. They accept ingress only from app: web pods; all other ingress is denied. Their egress is unchanged. Selecting a pod for Ingress isolates its ingress; the rule is the allow-list; egress is not isolated because Egress is not in policyTypes.
  2. Their egress is now also limited to app: web pods. Egress isolation happens only when Egress is listed in policyTypes.
  3. They accept ingress from app: web and everything else too; the policy only adds an allow. The first policy selecting a pod switches that direction to default-deny.
  4. They block traffic from app: web and allow everything else. Rules allow, never deny.
In short

The api pods now accept ingress only from app: web pods; their egress is not changed.

Why

Two facts explain every NetworkPolicy question: selection isolates a direction, and rules allow. With only Ingress in policyTypes, egress stays open.

Read the docs

4 Pick the strongest answer

Pods on the same node can reach each other; pods on different nodes cannot; the nodes ping each other fine. The CNI is Flannel with VXLAN. What do you suspect first?

  1. CoreDNS is down. Tests by IP would still fail; and DNS does not affect same-node vs cross-node.
  2. kube-proxy is not running on one node. kube-proxy implements Services, not pod-to-pod reachability.
  3. The cloud security group or host firewall blocks Flannel's VXLAN port, UDP 8472, between nodes, so encapsulated pod traffic is dropped while plain node traffic passes. Same-node traffic never leaves the host; cross-node traffic rides VXLAN on UDP 8472 (Flannel's default; the IANA VXLAN port is 4789), which is the differentiator.
  4. The pods lack a NetworkPolicy allowing cross-node traffic. Without policies, the model allows everything; and policies do not distinguish nodes.
In short

A firewall or security group is blocking the VXLAN UDP port (8472 for Flannel) between nodes, so cross-node pod traffic is dropped.

Why

Bisect by topology: same node works, cross node fails, nodes reach each other. What differs is the encapsulation path. Check security groups for the overlay port, then tcpdump -i eth0 udp port 8472 on the destination node.

Read the docs

5 Read the output

Small requests succeed and large ones hang across nodes. What is happening?

$ kubectl exec -n shop api-1 -- ip link show eth0 | grep mtu
2: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
$ ip link show eth0            # on the node
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP
$ ip link show flannel.1       # on the node
5: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN
$ kubectl exec -n shop api-1 -- curl -s -o /dev/null -w '%{http_code}\n' http://catalog.shop:8080/small
200
$ kubectl exec -n shop api-1 -- curl -s -o /dev/null -w '%{http_code}\n' --max-time 10 http://catalog.shop:8080/large
000
  1. A NetworkPolicy allows only small packets. NetworkPolicy has no notion of packet size.
  2. The catalog service is slow for large responses. A slow app returns eventually; a 000 with timeout on exactly large payloads is a packet-size problem.
  3. MTU mismatch: the pod interface advertises 1500 but the VXLAN path only carries 1450, so full-size packets are dropped, and the ICMP 'fragmentation needed' that path-MTU discovery relies on is evidently not reaching the sender, as is common across overlays and cloud filtering. The pod's eth0 MTU exceeds the overlay MTU; only responses big enough to need full-size packets fail.
  4. kube-proxy conntrack table is full. Conntrack exhaustion fails connections regardless of size.
In short

This is an MTU problem: the pod sends 1500-byte packets but the VXLAN link can only carry 1450, so big packets are dropped.

Why

VXLAN adds 50 bytes, so the overlay interface is 1450 while the pod thinks it has 1500. Path-MTU discovery would rescue this only if the ICMP 'fragmentation needed' message reached the sender, and across overlays and cloud security groups it usually does not, which is why the fix is to set the MTU rather than rely on discovery: set the CNI MTU to 1450 (or enable jumbo frames on the underlay so the overlay can carry 1500). ping -M do -s 1422 between pods confirms the ceiling.

Read the docs

6 Scenario: what do you do next?

Security asks for namespace isolation across a 40-team cluster by Friday: "no pod should talk to another team's namespace unless allowed". Today there are no NetworkPolicies. The CNI is the cloud provider's default plugin, which does not enforce NetworkPolicy. A previous attempt applied default-deny policies and 'nothing happened', so the team believes policies do not work.

Step 1. What do you establish first?

  1. Enable a service mesh. A large change for an isolation requirement NetworkPolicy already covers once enforced.
  2. Write default-deny policies for all 40 namespaces immediately. With no enforcement they do nothing; with enforcement and no allow rules they break everything on Friday.
  3. Whether policies are enforced at all: check the CNI's NetworkPolicy support, and test a default-deny in a scratch namespace by attempting a connection that should be blocked. Kubernetes accepts policy objects even when nothing enforces them; proving enforcement is the first fact, and it explains the earlier 'nothing happened'.
  4. Ask each team to list their dependencies in a spreadsheet. Useful later; not the first fact and rarely accurate.

Step 2. Confirmed: the default CNI does not enforce. What is the plan for the week?

  1. Tell security it cannot be done. It can; the timeline is the negotiation.
  2. Enable a policy-enforcing CNI or add-on (for example Calico or Cilium in policy mode on the provider's network), then roll out per-namespace default-deny with explicit allows for DNS, ingress from the ingress controller, and observed flows; use flow logs to discover dependencies before enforcing. Enforcement first, discovery from real flows, then deny with allows; reversible per namespace.
  3. Replace the CNI cluster-wide in one maintenance window on Thursday night. CNI replacement is a node-by-node operation with real risk; it should be staged, not rushed to a deadline.
  4. Block cross-namespace traffic at the cloud security-group level. Security groups do not see pod labels or namespaces; pods share node IPs on many CNIs.

Step 3. Isolation is live for 10 pilot namespaces. What makes this safe to extend to all 40?

  1. A policy template per namespace (default-deny + DNS + ingress-controller + monitoring scrape), flow logs reviewed for denied traffic in audit mode before enforce, a CI check that every namespace has the baseline, and an on-call runbook for 'my service cannot reach X'. Mechanisms that make the rollout repeatable, observable, and reversible; the runbook absorbs the inevitable missed dependency.
  2. Give each team cluster-admin so they can fix their own policies. Solves a networking rollout with a security regression.
  3. Enforce everywhere at once since the pilot worked. Pilot namespaces were chosen; the long tail has undocumented dependencies.
In short

First prove that policies are enforced at all, then roll out default-deny namespace by namespace with DNS always allowed.

Why

Most 'NetworkPolicy does not work' stories are unenforced policies. The interview shape: establish enforcement, discover flows before denying, template the baseline (always with DNS), stage by namespace with an audit mode, and make exceptions a runbook rather than a firefight.

Read the docs

7 Quick recall

You are about to apply a default-deny egress policy to a namespace. Which destination must the same change allow, or every workload in it breaks?

In short

Allow DNS: UDP and TCP port 53 to the CoreDNS (kube-dns) pods in kube-system.

Accepted

DNS · CoreDNS · kube-dns

Why

CoreDNS in kube-system on UDP and TCP 53; without it, egress isolation breaks name resolution for everything.

Next lesson RBAC, service account tokens, Pod Security Admission, secrets hygiene, and escalation paths
Drill · Pod networking, CNI, MTU, and NetworkPolicy semantics
0:00

Loading…