Portal | Level: L2: Operations | Topics: Kubernetes Networking | Domain: Kubernetes
Runbook: NetworkPolicy Blocking Traffic¶
Symptoms¶
- Application can't reach other services (timeouts)
- External requests to pods fail
- DNS resolution may also fail if egress is blocked
Fast Triage¶
# List all NetworkPolicies in namespace
kubectl get networkpolicy -n grokdevops
kubectl describe networkpolicy -n grokdevops
# Test connectivity from app pod
kubectl exec -n grokdevops deploy/grokdevops -- wget -qO- --timeout=3 http://grokdevops/health 2>&1 || echo "BLOCKED"
# Test DNS
kubectl exec -n grokdevops deploy/grokdevops -- nslookup kubernetes.default 2>&1 || echo "DNS BLOCKED"
# Check pod labels match policy selectors
kubectl get pods -n grokdevops --show-labels
Likely Causes (ranked)¶
- Deny-all policy applied — blocks all ingress/egress
- Missing egress rule for DNS — pods can't resolve names (need port 53 to kube-system)
- Label selector too broad — policy matches more pods than intended
- Chaos script left a policy —
training/interactive/chaos/scripts/toggle_networkpolicy.shapplied but not removed
Evidence Interpretation¶
What bad looks like:
$ kubectl exec -n grokdevops deploy/grokdevops -- wget -qO- --timeout=3 http://grokdevops/health
wget: download timed out
$ kubectl exec -n grokdevops deploy/grokdevops -- nslookup kubernetes.default
;; connection timed out; no servers could be reached
kubectl get networkpolicy -n grokdevops will list active policies. Check spec.podSelector to see which pods are affected.
Fix Steps¶
- Remove the offending policy:
- If it was a chaos script:
- If you need the policy but with DNS allowed, add egress for DNS:
Verification¶
Cleanup¶
kubectl get networkpolicy -n grokdevops -l chaos=true --no-headers | awk '{print $1}' | xargs -r kubectl delete networkpolicy -n grokdevops
Unknown Unknowns¶
- Without any NetworkPolicy in a namespace, all ingress and egress traffic is allowed. The moment you add ONE policy selecting a pod, that direction (ingress or egress) becomes default-deny for that pod.
- Adding a single egress policy that allows traffic to your database but forgets DNS (port 53/UDP) will break all name resolution for matched pods.
- NetworkPolicies are additive (union). Multiple policies selecting the same pod combine their allow rules — there is no way to write a "deny this specific traffic" policy, only "allow this."
- Policies are enforced by the CNI plugin. If the CNI doesn't support NetworkPolicy (e.g., default Flannel), policies are silently ignored.
[!WARNING] Any egress NetworkPolicy that does not explicitly allow UDP port 53 to kube-system will silently break DNS resolution for all matched pods. This is the most common NetworkPolicy mistake and the symptoms (connection timeouts) do not obviously point to DNS.
Pitfalls¶
- Forgetting DNS egress rule — the most common mistake. Any egress policy must include UDP port 53 or DNS breaks.
- Not checking if a chaos script left a policy — the chaos script
toggle_networkpolicy.shapplieschaos-deny-all. Check for policies with labelchaos=true. - Applying deny-all without exception rules — a deny-all ingress + egress policy with no additional allow policies will isolate pods completely, including from DNS and health checks.
See Also¶
training/interactive/exercises/levels/level-25/k8s-networkpolicy/training/interactive/chaos/scripts/toggle_networkpolicy.shtraining/interactive/incidents/scenarios/networkpolicy-block-ingress.sh
Wiki Navigation¶
Related Content¶
- API Gateways & Ingress (Topic Pack, L2) — Kubernetes Networking
- Case Study: CNI Broken After Restart (Case Study, L2) — Kubernetes Networking
- Case Study: Canary Deploy Routing to Wrong Backend — Ingress Misconfigured (Case Study, L2) — Kubernetes Networking
- Case Study: CoreDNS Timeout Pod DNS (Case Study, L2) — Kubernetes Networking
- Case Study: Grafana Dashboard Empty — Prometheus Blocked by NetworkPolicy (Case Study, L2) — Kubernetes Networking
- Case Study: Service Mesh 503s — Envoy Misconfigured, RBAC Policy (Case Study, L2) — Kubernetes Networking
- Case Study: Service No Endpoints (Case Study, L1) — Kubernetes Networking
- Cilium & eBPF Networking (Topic Pack, L2) — Kubernetes Networking
- Deep Dive: Kubernetes Networking (deep_dive, L2) — Kubernetes Networking
- Docker Networking Flashcards (CLI) (flashcard_deck, L1) — Kubernetes Networking