🎯 What It Is

Even with correct YAML, NetworkPolicies can fail silently. This topic covers how to debug and apply production-grade practices.

βœ… Goal: Go from β€œwhy isn’t this working?” to β€œtraffic flows exactly as intended.”

πŸ’‘ Real-World Analogy

Like a network engineer with a packet sniffer:


πŸ§ͺ Step-by-Step Troubleshooting Guide

πŸ” Step 1: Confirm Your CNI Supports NetworkPolicy

# Check if Cilium/Calico is running
kubectl get pods -n kube-system | grep -E 'cilium|calico'

# If using Flannel (default in k3s) β†’ NetworkPolicy **won’t work!**

βœ… Fix: Install Cilium:

curl -L --remote-name <https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz>
tar xzvfC cilium-linux-amd64.tar.gz /usr/local/bin
cilium install


πŸ” Step 2: Verify Policy Is Applied to the Right Pods

# Check if policy matches your Pod labels
kubectl describe netpol my-policy

# List Pods that should be affected
kubectl get pods -l app=backend

βœ… Common mistake: Typo in labels (app: backned vs app: backend)


πŸ” Step 3: Test Connectivity Manually

# Start a debug Pod in the same namespace
kubectl run debug --image=busybox --rm -it -- sh

# Test ingress: can others reach target?
/ # wget -qO- <http://backend> --timeout=3

# Test egress: can target reach others?
kubectl exec deploy/backend -- wget -qO- <http://database> --timeout=3

βœ… Use --timeout to avoid hanging