| name | debugging-k8s-networking |
| description | Debugs Kubernetes networking issues including Service connectivity, DNS resolution, Ingress routing, Endpoints, and NetworkPolicy. Use when services are unreachable, DNS fails, ingress not routing, or network connectivity problems. |
| allowed-tools | Bash |
Debugging Kubernetes Networking
Investigates Service, DNS, Ingress, and connectivity issues.
Common Network Issues
| Symptom | Likely Cause | First Check |
|---|
| Service unreachable | No endpoints, selector mismatch | Endpoints exist |
| DNS not resolving | CoreDNS issue, wrong service name | DNS from inside pod |
| Ingress not routing | Missing backend, TLS issue | Ingress + Service config |
| Connection refused | Pod not listening, wrong port | Target port matches |
| Connection timeout | NetworkPolicy blocking | NetworkPolicy rules |
Investigation Workflow
Step 1: Verify Service and Endpoints
kubectl get svc <service> -n <ns>
kubectl get endpoints <service> -n <ns>
kubectl describe svc <service> -n <ns>
No endpoints? Check:
- Service selector matches pod labels
- Pods are Running and Ready
kubectl get svc <service> -n <ns> -o jsonpath='{.spec.selector}'
kubectl get pods -n <ns> --show-labels
Step 2: Test DNS Resolution
kubectl exec -it <pod> -n <ns> -- nslookup <service>
kubectl exec -it <pod> -n <ns> -- nslookup <service>.<namespace>.svc.cluster.local
kubectl get pods -n kube-system -l k8s-app=kube-dns
DNS format: <service>.<namespace>.svc.cluster.local
Step 3: Test Connectivity
kubectl exec -it <pod> -n <ns> -- wget -qO- --timeout=5 http://<service>:<port>/
kubectl exec -it <pod> -n <ns> -- nc -zv <service> <port>
kubectl exec -it <pod> -n <ns> -- curl -s --max-time 5 http://<service>:<port>/
Step 4: Check NetworkPolicy
kubectl get networkpolicy -n <ns>
kubectl describe networkpolicy <policy> -n <ns>
NetworkPolicy can block:
- Ingress (incoming to pod)
- Egress (outgoing from pod)
Specific Issues
Service Has No Endpoints
kubectl get svc <service> -n <ns> -o jsonpath='{.spec.selector}'
kubectl get pods -n <ns> -l <key>=<value>
kubectl get pods -n <ns> -o wide
Ingress Not Working
kubectl get ingress -n <ns>
kubectl describe ingress <ingress> -n <ns>
kubectl logs -n <ingress-ns> -l app.kubernetes.io/name=ingress-nginx --tail=50
Common ingress issues:
- Backend service doesn't exist
- Service port mismatch
- TLS secret missing
- Ingress class not specified
kubectl get ingressclass
Port Mismatch
kubectl get svc <service> -n <ns> -o jsonpath='{.spec.ports[*].targetPort}'
kubectl get pod <pod> -n <ns> -o jsonpath='{.spec.containers[*].ports[*].containerPort}'
Pod Not Listening
kubectl get pod <pod> -n <ns> -o jsonpath='{.spec.containers[*].ports}'
kubectl exec -it <pod> -n <ns> -- netstat -tlnp 2>/dev/null || kubectl exec -it <pod> -n <ns> -- ss -tlnp
Quick Debug Commands
kubectl get svc,ep -n <ns>
kubectl get ingress -A
kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup <service>.<ns>.svc.cluster.local
Notes
- Load
analyzing-k8s-events to check for network-related events
- Load
debugging-k8s-pods if the target pods are not healthy