After adding a NetworkPolicy that allows ingress to `backend` from `frontend`, the frontend still can't connect.
AdvancedTroubleshootingContainers, Kubernetes, IPv6 and packet captures
Answer
Likely causes → A default-deny egress policy in the frontend namespace blocks the outgoing side (both ends must allow), the selectors are wrong, or the rule semantics are off: namespaceSelector and podSelector in the same from item mean AND, in separate items they mean OR. Also, the policy needs the pod port (targetPort), not the Service port.
Diagnose →
kubectl get networkpolicy -A
kubectl describe networkpolicy allow-frontend -n backend
kubectl get ns frontend --show-labels # kubernetes.io/metadata.name=frontend
kubectl exec -n frontend deploy/frontend -- nc -vz -w3 backend.backend.svc 8080
Fix →
ingress:
- from:
- namespaceSelector:
matchLabels: {kubernetes.io/metadata.name: frontend}
podSelector:
matchLabels: {app: frontend}
ports:
- port: 8080
And add an egress policy in frontend allowing traffic to backend on 8080 (plus DNS to kube-system on 53).
Prevent → Use a policy visualiser (Cilium editor, kubectl np-viewer) and policy tests in CI.
More on Containers, Kubernetes, IPv6 and packet captures
After someone ran `iptables -F` (or restarted firewalld), all Docker containers lost outbound connectivity.Intermediate`docker run -p 8080:80 myapp` starts fine, but `curl localhost:8080` returns `Connection reset by peer`.BeginnerTwo containers on the default bridge network can't reach each other by container name.Beginner`docker run -p 80:80 nginx` fails with `Bind for 0.0.0.0:80 failed: port is already allocated`.BeginnerA new Kubernetes node stays `NotReady` with `container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized`.IntermediateA Service returns `Connection refused` / nothing, and `kubectl get endpoints myapp` shows `<none>`.Beginner