Interview Prep/Networking/Containers, Kubernetes, IPv6 and packet captures

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.

All Networking questions Roadmap: Networking for DevOps

More on Containers, Kubernetes, IPv6 and packet captures