Kubernetes NetworkPolicy Troubleshooting: Fix Blocked Pods, Broken DNS and Silent CNI Gaps
Kubernetes NetworkPolicy troubleshooting starts with one question: which policies select this pod, and does the CNI enforce them at all? This guide walks the failure modes that bite in production: default-deny breaking DNS egress, label and selector mismatches, the AND versus OR peer trap, ipBlock and except mistakes on external egress, and CNIs that accept policies without enforcing them, with kubectl checks and YAML fixes for each case.
1. What Kubernetes NetworkPolicy troubleshooting actually checks
Kubernetes NetworkPolicy troubleshooting checks three things in order: whether the CNI enforces policies at all, which policies select the affected pod, and whether the union of their allow rules covers the failing flow. Most outages come from a default-deny policy, a forgotten DNS egress rule, or a selector that matches nothing.
Illustrative composite: a platform team rolls out namespace segmentation on a Friday. The payments namespace gets a default-deny policy plus allow rules for the API tier and the database. Within minutes every pod is still Running and Ready, readiness probes pass, yet checkout requests fail with name-resolution timeouts against services in the same namespace. Direct pod-IP calls work. The allow rules were fine; nobody allowed egress to CoreDNS on port 53, so every lookup timed out before a single connection was attempted. That pattern, healthy pods with dead name resolution right after a policy change, is the single most common NetworkPolicy incident, and it sets the order of this guide: enforcement first, selection second, rules third.
Keep the symptom split in mind while you work. A connection that times out usually means packets are being dropped, which is what policy enforcement does. A connection refused means something answered and rejected, which points at the application, a missing listener, or a Service with no endpoints rather than a policy. Name-resolution failures with working IP connectivity point at DNS egress. Traffic that flows despite a deny policy points at a CNI that is not enforcing. Each symptom narrows the search before you read a single line of YAML, and the kubectl master guide covers the exec and describe patterns used throughout this runbook.
One more framing point matters for every section that follows. NetworkPolicy is an allow-list system with no explicit deny rules. There is no rule you can write that says block this flow. Denial is what happens to everything the allow rules fail to cover once a pod is selected for a direction. Troubleshooting therefore means auditing coverage: find every policy that selects the pod, union the allowed peers and ports, and check whether your failing flow is inside that union on both the source egress side and the destination ingress side.
2. How NetworkPolicy decides allow or deny
NetworkPolicy troubleshooting depends on one mechanism: a pod with no selecting policy allows all traffic, but the moment any policy selects it for a direction, that direction becomes deny-by-default and only the union of all allow rules passes. Policies are additive, namespace-scoped, and enforced by the CNI at layer 3 and 4.
The selection model is where most confusion starts. A policy lives in one namespace and its top-level podSelector picks pods in that namespace only. podSelector: {} selects every pod in the namespace. A matchLabels selector picks pods carrying those labels. If no policy in the namespace selects a pod for ingress, all ingress is allowed. Add one policy that selects it with Ingress in policyTypes, and ingress flips to deny-by-default: only peers and ports named in some selecting policy's ingress rules get through. Egress works the same way, independently. A pod can be isolated for ingress while egress stays wide open, and vice versa.
policyTypes deserves attention because its defaults surprise people. If you omit policyTypes, Kubernetes infers Ingress always, and infers Egress only when the policy contains an egress field. A policy written to allow one ingress port, with no policyTypes and no egress field, therefore isolates ingress but leaves egress untouched. The reverse mistake also happens: an egress allow policy that includes an egress field silently turns on egress isolation, and every other outbound flow, DNS included, stops working. When a change breaks traffic in a direction nobody meant to touch, check the inferred policy types first.
Additivity is the other half of the mechanism. When several policies select the same pod, the effective rule set is the union of all their allow rules. No policy can subtract from another. This means a leftover permissive policy quietly defeats a strict one, and deleting a default-deny policy does not restore openness if another selecting policy still isolates the pod. It also means debugging is a set-union exercise, not a first-match firewall walk. The CNI comparison guide explains how Calico and Cilium compile these unions into iptables, nftables, or eBPF datapath rules, which is useful when you later read CNI logs.
Two scope limits complete the picture. NetworkPolicy sees IP addresses, ports, and protocols only; it has no concept of HTTP paths, hostnames, or TLS SNI, so hostname-based egress control needs a CNI extension such as Cilium DNS policies or an egress proxy. And traffic to or from the node a pod runs on is always allowed, which is why kubelet probes keep passing during a policy outage: the probe arrives from the node, not from another pod, so readiness stays green while pod-to-pod traffic dies. That detail explains the most misleading symptom in this whole area, a fully Ready workload that cannot talk to anything.
3. Step 1 of NetworkPolicy troubleshooting: prove the CNI enforces policies
NetworkPolicy troubleshooting starts with enforcement because a policy on a non-enforcing CNI is accepted by the API and does nothing. Flannel alone, kubenet, and kindnet ignore policies, and managed clusters often need an explicit switch. Prove enforcement with a deny test before debugging rules.
The API server validates NetworkPolicy objects but never enforces them; enforcement is entirely the CNI plugin's job. Calico, Cilium, Antrea, and kube-router enforce natively. Plain Flannel does not, although Flannel paired with Calico's policy engine (the Canal combination) does. Managed Kubernetes adds a second trap: enforcement is frequently opt-in. On EKS, the Amazon VPC CNI enforces policies only when its network policy controller is enabled. On GKE, policy enforcement depends on Dataplane V2 or the Calico add-on being active. On AKS, the Azure Network Policy Manager or Calico must be selected. In every one of these cases kubectl apply succeeds, the object exists, and traffic flows as if the policy were absent, which reads exactly like a rules bug until you test enforcement directly.
Identify the CNI first, then run a controlled deny test in a scratch namespace:
Apply a default-deny ingress policy to the web pod and confirm the client can no longer reach it:
If the request still succeeds, stop. No amount of YAML editing will help until the CNI enforces, and the fix is a cluster-level change: enable the policy controller, switch the CNI, or add a policy engine beside Flannel. If the request times out, enforcement works and the problem lives in selection or rules, which the next steps cover. For the datapath differences behind these checks, see the Kubernetes CNI guide. One caution on scope: a test in one namespace proves the CNI enforces in that namespace. Some multi-tenant setups scope enforcement per namespace or per node pool, so repeat the test where the incident is happening if the first result looks too clean.
4. Step 2 of NetworkPolicy troubleshooting: find every selecting policy
NetworkPolicy troubleshooting fails when engineers read one policy and miss the others selecting the same pod. List every policy in the namespace, match each top-level podSelector against the pod's labels, and build the union of allowed peers and ports for each direction before changing anything.
Start with the pod's labels and the namespace's policies side by side:
kubectl describe networkpolicy renders each policy in a readable form, which helps when the YAML is long:
The describe output shows the pod selector, policy types, and the ingress and egress rules in plain text. Read it as an auditor: for the failing flow, you need an egress allowance on the source pod and an ingress allowance on the destination pod. Either side missing means dropped packets. Many incidents turn out to be one-sided fixes, where the team added an egress rule on the caller and forgot the ingress rule on the callee, or the reverse.
Selection matching is mechanical, so do it mechanically. For each policy in the namespace, ask whether its top-level podSelector matches the pod's labels. An empty selector matches everything. A matchLabels selector requires every listed label to be present with the exact value. A matchExpressions selector adds set-based conditions. Collect every matching policy, split them by direction using policyTypes (remembering the inference rule when the field is absent), and union the rules. If the union for a direction is empty, that direction is fully denied for the pod. If the failing peer or port is absent from the union, you have found the gap.
Labels are the weak link in this process. A Deployment template change that renames app: checkout to app.kubernetes.io/name: checkout silently unselects every policy written against the old label, and the pod falls back to allow-all, or the reverse: a new label value pulls a pod under a strict policy it was never meant to join. Compare the labels on the running pod, not the labels in the Deployment you think is deployed, and check for label drift after rollouts. The Service no-endpoints guide covers the same label-drift failure from the Service selector side, and the two bugs often arrive together after a template refactor.
A quick scripted pass helps on larger namespaces. This lists policies whose selector is empty, which are the ones isolating the whole namespace:
Treat that output as your default-deny inventory. Any namespace-wide isolation comes from those policies, and every allow rule in the namespace exists to punch holes in them.
5. Default-deny traps in NetworkPolicy troubleshooting
Default-deny is where NetworkPolicy troubleshooting usually lands: a namespace-wide policy with an empty podSelector isolates every pod, and each forgotten allow rule becomes an outage. Check policyTypes coverage, empty rule lists, and whether both directions were isolated when only one was intended.
The canonical default-deny policy is short, and its brevity hides the blast radius:
With no ingress or egress rules, every pod in payments is isolated in both directions. That is the correct starting point for segmentation, but it means the allow set must be complete before the policy lands: DNS egress, ingress from the ingress controller namespace, egress to databases and external APIs, metrics scraping ingress, and any sidecar or init-container traffic. Rollouts that apply default-deny first and allows second produce a guaranteed outage window. Apply allows first, verify, then apply the deny.
Three variants cause recurring confusion. First, a policy with policyTypes: [Ingress] and an empty ingress: [] list denies all ingress, while the same policy with the ingress field absent does the same thing; the empty list and the missing field are equivalent once the direction is isolated. Second, a policy that selects pods and lists Ingress but omits Egress leaves egress fully open, which surprises teams who assume one policy locks both directions. Third, an allow-all rule written as ingress: [{}] or a peer of podSelector: {} reopens everything for the selected pods, and because policies are additive, that single permissive rule defeats a strict default-deny in the same namespace. Auditing for accidental allow-alls is as important as auditing for missing allows.
Direction asymmetry produces a distinctive symptom worth memorizing. If egress is isolated but ingress is not, pods can receive traffic but cannot reply usefully to anything that needs a new outbound connection, and DNS dies first. If ingress is isolated but egress is not, pods can call out but nothing can call in, so Services time out while outbound jobs keep working. Map the symptom to the isolated direction before reading rules; it halves the search space.
Also check who else shares the namespace. Default-deny selects every pod, including debug pods, CronJob pods, and sidecars injected later. A backup CronJob that worked for months breaks the day segmentation lands because nobody wrote its egress rule. Inventory the namespace's workloads, including jobs and DaemonSet pods, and confirm each has its allowances. The container networking troubleshooting guide covers the lower-layer checks to run when policy coverage looks correct but packets still drop.
6. DNS egress in NetworkPolicy troubleshooting: the first default-deny break
In NetworkPolicy troubleshooting, DNS failure after a policy change almost always means egress to CoreDNS on port 53 is not allowed. Allow UDP and TCP 53 to the kube-dns pods in kube-system, selecting them with a combined namespaceSelector and podSelector peer, and test resolution from inside the pod.
DNS is traffic, and egress isolation treats it like everything else. A pod sends queries to the cluster DNS Service IP, kube-proxy or the CNI datapath translates that to a CoreDNS pod IP, and policy evaluation happens against the translated destination in most CNIs. That translation detail kills two common fix attempts. An ipBlock rule naming the DNS Service IP usually fails because the policy engine sees the CoreDNS pod IP after DNAT. A podSelector alone fails because CoreDNS pods live in kube-system, outside the policy's namespace, and a bare podSelector only matches pods in the policy's own namespace.
The working shape combines both selectors in one peer, which means pods with the DNS label inside the kube-system namespace:
Both protocols matter. Most queries ride UDP, but large responses truncate and retry over TCP, and some resolvers use TCP from the start. Allowing only UDP produces the maddening variant where most names resolve and a few, usually ones with many records, hang. The kubernetes.io/metadata.name label is applied automatically to every namespace since Kubernetes 1.21, so it is the reliable way to name a namespace in a selector; verify your CoreDNS pod label with kubectl get pods -n kube-system --show-labels, because distributions differ (k8s-app: kube-dns is the common one).
Test from inside the affected pod, not from your workstation:
A timeout against the DNS server address on port 53 confirms the egress gap. If the image has no shell or lookup tools, use an ephemeral debug container, which shares the pod's network namespace and therefore the same policy:
Client behavior varies enough to mislead triage. Go's resolver can wait around 40 seconds before failing, glibc-based tools fail faster, and some libraries cache the failure and keep erroring after the policy is fixed until the pod restarts. When resolution works from a debug container but the application still fails, restart the pod before doubting the fix. For CoreDNS-side causes that mimic policy failures, such as ndots search-domain blowups, work through the Kubernetes DNS troubleshooting guide after the egress rule is confirmed.
7. Selector mismatches in NetworkPolicy troubleshooting: labels and namespaces
Selector mismatches are the quiet core of NetworkPolicy troubleshooting: a rule that matches no pods allows nothing, and the API never warns you. Verify every podSelector against live pod labels and every namespaceSelector against live namespace labels, including the automatic kubernetes.io/metadata.name label.
A NetworkPolicy peer matches on labels, and labels are exact-match strings. app: checkout does not match app: checkout-api. A selector written against app.kubernetes.io/name does not match pods labeled only app. Nothing validates that a selector matches anything, so a typo produces a policy that applies cleanly and allows zero traffic. The symptom is a flow that stays blocked after the fix was supposedly applied, which sends teams back to the CNI when the real problem is a label that does not exist.
Verify selectors against the live objects, in both directions of the flow:
The -l queries are the fastest selector test available: if kubectl get pods -l app=checkout returns nothing in the namespace, any peer using that selector matches nothing either. Run the same test for the destination pod's labels and for namespace labels before editing YAML.
Namespace selectors have their own trap. A namespaceSelector matches namespaces by their labels, and a namespace with no custom labels matches only through the automatic kubernetes.io/metadata.name label. Teams often write namespaceSelector: { matchLabels: { name: monitoring } } assuming a name label exists; unless someone applied that label, the peer matches no namespace and the rule is dead. An empty namespaceSelector: {} matches all namespaces, which is sometimes intended for DNS or monitoring allowances and sometimes an accidental wide-open rule. Read empty selectors carefully in both directions: podSelector: {} in a peer means all pods in the policy's namespace, namespaceSelector: {} means all pods in all namespaces.
The top-level selector and the peer selectors fail differently, and the difference matters. A top-level podSelector that matches nothing means the policy isolates nobody, so traffic flows freely and the failure looks like missing enforcement. A peer selector that matches nothing means the policy isolates its pods but allows nobody, so traffic stops and the failure looks like an over-strict deny. When traffic flows that should be blocked, suspect the top-level selector. When traffic is blocked that should flow, suspect the peers. That one distinction routes most selector bugs correctly on the first pass.
Label governance prevents the whole class. Standardize on the app.kubernetes.io/* labels, keep policy selectors in the same repository as the workloads they select, and add a CI check that renders policies and asserts each selector matches at least one pod template. The Kubernetes Services guide shows how Service selectors use the same label mechanics, and teams that govern labels for Services rarely suffer policy selector drift.
8. The AND vs OR peer trap in NetworkPolicy troubleshooting
The most expensive YAML mistake in NetworkPolicy troubleshooting is one dash: namespaceSelector and podSelector in the same peer entry mean AND, while separate list entries mean OR. The OR form silently allows far more traffic than intended, and the AND form is what cross-namespace rules almost always need.
Consider the rule most people mean to write: allow traffic from Prometheus pods in the monitoring namespace. The correct form puts both selectors in one peer entry:
One list entry carrying both selectors means pods labeled app: prometheus inside namespaces labeled as monitoring. Now the broken variant, differing by a single dash:
Two list entries mean OR: every pod in the monitoring namespace, plus every pod labeled app: prometheus in the policy's own namespace. The rule now allows far more than intended, and because the intended traffic still works, nobody notices until an audit or an incident exposes the wider opening. The reverse error also occurs: a team writes the AND form when they wanted same-namespace pods, and traffic from local pods stays blocked because the namespace condition excludes them.
The same semantics apply on the egress side with to: peers, and to matchExpressions inside each selector. The mental model is set logic: fields within one peer entry intersect, entries within the peer list union, and rules within the policy union again. When reviewing a policy, read each peer entry as a single AND statement and each dash as an OR.
Two habits catch this bug class. First, format policies so the structure is visible: keep both selectors of an AND peer at the same indentation with no dash between them, and review the rendered YAML after Helm or Kustomize processing, since templating can reformat lists in ways that hide the dash placement. Second, test the negative case, not only the positive one. After applying a cross-namespace allow, verify that a pod in the right namespace with the wrong label is still blocked, and that a pod with the right label in the wrong namespace is still blocked. A rule that passes only the positive test may be the OR form in disguise.
Policy linters and admission checks can flag the pattern mechanically: any peer list containing a bare namespaceSelector entry beside a bare podSelector entry deserves a human look. It is occasionally intentional, for example allowing all monitoring pods plus a local debug label, but it should be a decision, not an accident of indentation.
9. Ports, named ports and protocol mistakes
Port mistakes in NetworkPolicy troubleshooting hide in plain sight: the rule allows the Service port while the pod listens elsewhere, a named port resolves differently than expected, or TCP is allowed while the flow needs UDP. Match policy ports to the destination pod's container ports and protocol, then test with the real port.
NetworkPolicy ports describe the destination pod's ports after Service translation. A Service can expose port 80 and forward to container port 8080; the policy must allow 8080, because enforcement happens at the pod. Rules written against the Service port are a classic cause of a flow that stays blocked after an allow rule was added. Read the destination pod's container ports and the Service's targetPort together:
Named ports add a resolution step. A policy port can be a name, such as port: http, and it resolves against the destination pod's named container ports. If the pod names its port web while the policy says http, the rule matches nothing. Named ports are worth using when several workloads share a policy template, but the name must exist on every selected pod. When a named-port rule misbehaves, temporarily rewrite it with the numeric port to remove resolution from the suspect list.
Protocol defaults bite in the same quiet way. A port entry without a protocol means TCP. DNS needs UDP and TCP. Some service meshes, logging agents, and game or VoIP workloads use UDP or SCTP. A rule that allows port 53 with no protocol allows TCP 53 only, and most DNS still fails. Write the protocol explicitly on every port entry so reviewers see the intent.
Port ranges use endPort, available since Kubernetes 1.21 in the v1 API:
Ranges suit sidecars and agents that bind a block of ports, but keep them narrow; a wide range is an allow-all wearing a smaller hat. Also remember what a missing ports field means: a rule with peers but no ports allows all ports from those peers, and a rule with ports but no peers allows those ports from everywhere. Both forms are occasionally correct and frequently accidental. In review, treat a rule missing either field as a deliberate wide opening that needs a comment explaining why.
Finally, test the port you think you opened, from the pod that should reach it, with a bounded timeout:
A timeout means packets drop somewhere along the policy path. A refused connection means the packet arrived and nothing listened, which moves the investigation to the application and its Service endpoints rather than policy.
10. ipBlock and except in NetworkPolicy troubleshooting: external egress
Egress failures dominate NetworkPolicy troubleshooting for external APIs: ipBlock rules match post-DNAT addresses, except ranges carve holes that swallow the target, and DNS-based endpoints change IPs under static CIDRs. Use ipBlock for true external CIDRs, selectors for in-cluster traffic, and test from the pod.
ipBlock peers match CIDR ranges and exist for destinations outside the selector system: external APIs, cloud metadata endpoints, partner networks, node IPs. Two properties cause most failures. First, evaluation happens against the address after Service DNAT in most CNIs, so an ipBlock naming a ClusterIP does not reliably match traffic to that Service; use pod and namespace selectors for in-cluster destinations and reserve ipBlock for traffic leaving the cluster. Second, except subtracts ranges from the CIDR, and the subtraction is literal. The common pattern allows public egress while excluding private ranges:
This works until the external endpoint resolves, through a load balancer or hairpin route, to an address inside an excepted range, at which point the allow evaporates and the connection times out while DNS and routing look perfect. The debugging tell is precise: resolution succeeds, a direct connection to the resolved IP fails, and removing the except block or the policy restores service instantly. Check what the name actually resolves to from inside the pod, and whether that address falls in an excepted range, before rewriting rules.
DNS-based external endpoints are the structural limit of ipBlock. A public API behind a CDN or a rotating load balancer changes addresses without notice, and a CIDR allowlist rots silently. Standard NetworkPolicy has no hostname concept, so the durable options are an egress proxy that enforces FQDN rules, or a CNI extension such as Cilium's DNS-aware policies that learn addresses from DNS responses. Pinning today's resolved IP in a CIDR is a short-term unblock, not a fix, and it should carry an expiry comment.
Order of operations for external egress debugging: resolve the name from the pod, connect to the resolved IP on the port, then connect by name. If resolution fails, you are back in DNS egress territory. If the IP connection fails but in-cluster traffic works, examine the ipBlock CIDR and except list against the resolved address. If the IP works and the name fails, suspect TLS SNI filtering at a proxy or a resolver difference, not NetworkPolicy. Keep example domains neutral in tests, such as api.example.com, and replace them with the real endpoint only in the live check.
One more egress subtlety: return traffic for allowed outbound connections is permitted by connection tracking, so you do not need an ingress rule for replies. If replies fail while the outbound SYN leaves, look at conntrack pressure or asymmetric routing on the node rather than adding ingress allows. The container networking guide covers those node-level checks.
11. Testing from inside the pod during NetworkPolicy troubleshooting
NetworkPolicy troubleshooting ends with evidence, not inference: run bounded connection tests from the source pod, compare IP and name-based results, then read CNI verdicts or logs to see which policy dropped the packet. Each test should change exactly one variable.
Build a small test matrix per flow and run it from the source pod's network namespace. Using kubectl exec into the real pod is best; an ephemeral debug container is the fallback when the image lacks tools. A temporary netshoot pod in the same namespace with the same labels is the third option, and matching labels matters, because a test pod with different labels is selected by different policies and proves nothing about the real workload.
Read the pattern, not the individual result. Name fails, IP works: DNS egress. Name and Service fail, pod IP works: Service translation or endpoint problem, not policy. Everything times out: policy drop on egress, ingress, or both. Connection refused: the packet arrived; look at the listener. Works from the test pod, fails from the real pod: label difference between the two pods.
When the tests say drop but the YAML says allow, ask the CNI what it decided. Cilium exposes flow verdicts through Hubble:
Calico exposes policy and endpoint state through calicoctl where available, and its node logs record policy programming errors:
Programming errors matter because a policy can exist in the API while the node agent failed to apply it, producing per-node behavior differences: the flow works from pods on one node and fails from another. Node-dependent symptoms are the signature. Test from pods on different nodes before concluding a rule is wrong.
Finish by testing the negative cases. Confirm a flow that should be blocked still times out after your fix. NetworkPolicy changes are additive, so a fix that opens the intended flow can also open unintended ones, especially when the fix was a broad selector. The verification is complete only when the allowed flow passes and a representative denied flow still drops. Record both results in the change ticket; future audits will ask.
12. NetworkPolicy troubleshooting matrix and final checklist
NetworkPolicy troubleshooting converges on a short matrix: match the symptom to the layer, run the listed check, and apply the smallest fix. Timeout means drop, refused means arrival, name-only failure means DNS egress, and traffic flowing past a deny means enforcement is missing.
| Symptom | Likely layer | First check | Fix |
|---|---|---|---|
| All names time out after a policy change, IPs work | DNS egress | nslookup from the pod |
Allow UDP+TCP 53 to kube-dns pods |
| One flow times out, others work | Missing allow on one side | Union of egress and ingress rules | Add the missing peer/port rule |
| Traffic flows despite deny policy | CNI not enforcing | Deny test in a scratch namespace | Enable policy controller or change CNI |
| Flow works from one node, fails from another | Node agent programming | CNI logs on both nodes | Fix agent errors, retest per node |
| External API times out, DNS resolves | ipBlock/except mismatch | Resolved IP vs except ranges | Correct CIDR or use FQDN egress control |
| Cross-namespace rule allows too much | AND vs OR peer form | Peer list structure | Merge selectors into one peer entry |
| Connection refused | Application or endpoints | Listener and Service endpoints | Fix the workload, not the policy |
| Works from test pod, fails from real pod | Label difference | --show-labels on both pods |
Align labels or selectors |
The decision table for choosing the right mechanism keeps fixes minimal:
| Need | Mechanism | Watch out for |
|---|---|---|
| Namespace baseline isolation | Default-deny plus explicit allows | Apply allows before the deny |
| Pod-to-pod allowance | podSelector peer | Label drift after rollouts |
| Cross-namespace allowance | namespaceSelector + podSelector in one peer | The OR dash trap |
| External API egress | ipBlock with except, or FQDN-aware egress | Rotating IPs, hairpin addresses |
| Hostname-based control | Cilium DNS policy or egress proxy | Standard NetworkPolicy cannot do this |
| L7 rules | Service mesh or Cilium L7 policy | NetworkPolicy stops at L4 |
Final checklist before closing a NetworkPolicy incident:
- Enforcement proven with a deny test in the affected namespace.
- Every policy selecting the source and destination pods listed, with the union of rules per direction written down.
- DNS egress allowed on UDP and TCP 53 to the CoreDNS pods, tested by name from the pod.
- Selectors verified against live pod and namespace labels with
-lqueries. - Cross-namespace peers checked for the AND form; negative cases tested.
- Policy ports matched to container ports and protocols, including named-port resolution.
- External egress checked against resolved IPs and except ranges; FQDN control chosen where IPs rotate.
- Allowed flow passes and a representative denied flow still drops, from pods on more than one node.
- Policies stored with the workloads they select, so label changes and policy changes review together.
Segmentation done this way stays boring, which is the goal. The failures in this guide all come from the same root: policies are easy to apply and hard to see. Keep the union of rules visible, test from inside the pod, and let the matrix route the next incident before anyone edits YAML on a hunch.
Frequently Asked Questions
What is Kubernetes NetworkPolicy troubleshooting and where do I start?
Kubernetes NetworkPolicy troubleshooting is the process of finding why pod traffic is dropped or unexpectedly allowed. Start by proving the CNI enforces policies with a deny test, then list every policy selecting the affected pod, then check whether the union of allow rules covers the failing flow on both the egress and ingress sides.
In NetworkPolicy troubleshooting, why does DNS stop working after a default-deny policy?
A default-deny egress policy blocks all outbound traffic, including DNS queries to CoreDNS on port 53. Pods stay Ready because kubelet probes come from the node, but every name lookup times out. Fix it with an egress rule allowing UDP and TCP 53 to the kube-dns pods in kube-system.
Why is my NetworkPolicy not working even though kubectl applied it?
The most common reason is a CNI that does not enforce NetworkPolicy. Flannel alone, kubenet, and kindnet ignore policies, and EKS, GKE, and AKS often need an explicit policy controller switch. The other common cause is a top-level podSelector that matches no pods, so the policy isolates nobody.
What is the difference between namespaceSelector and podSelector in NetworkPolicy troubleshooting?
A podSelector matches pods by label inside the policy's own namespace. A namespaceSelector matches namespaces by label and covers all pods in them. Combined in one peer entry they mean pods with that label in those namespaces; as separate list entries they mean either condition, which allows much more traffic.
How do I allow egress to an external API in NetworkPolicy troubleshooting?
Use an ipBlock peer with the API's CIDR range on TCP 443, excluding private ranges with except if needed, and keep DNS egress allowed. Because standard NetworkPolicy matches IPs only, APIs with rotating addresses need FQDN-aware egress through Cilium DNS policies or an egress proxy instead of static CIDRs.
How do I debug NetworkPolicy with kubectl?
Run kubectl get networkpolicy in the namespace, kubectl describe networkpolicy for the selecting policies, and kubectl get pods --show-labels to verify selectors. Then test from inside the source pod with nslookup, curl to the Service name, and curl to the pod IP, and read CNI logs or Hubble verdicts for drops.
Why can pods reach each other by IP but not by Service name after a policy change?
IP connectivity working while names fail means DNS egress is blocked, because the connection itself is allowed but resolution never completes. Allow egress on UDP and TCP 53 to the CoreDNS pods. If names resolve but the Service still fails while pod IPs work, check Service endpoints instead of policy.
Preparing for Senior Platform & SRE Interviews
Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.
Explore Interview Scenarios →