Networking Troubleshooting Scenarios¶
Real-world networking troubleshooting scenarios for CKA/CKS exam preparation.
Scenario 1: DNS Resolution Failing¶
Problem¶
Diagnosis Steps¶
# 1. Check CoreDNS pods
kubectl get pods -n kube-system -l k8s-app=kube-dns
# 2. Check CoreDNS logs
kubectl logs -n kube-system -l k8s-app=kube-dns
# 3. Check CoreDNS service
kubectl get svc -n kube-system kube-dns
# 4. Check endpoints
kubectl get endpoints -n kube-system kube-dns
Solutions¶
CoreDNS pods not running
CoreDNS ConfigMap issue
Scenario 2: Pod Cannot Reach External Network¶
Problem¶
Diagnosis Steps¶
# 1. Check pod DNS config
kubectl exec test-pod -- cat /etc/resolv.conf
# 2. Check if pod can reach DNS
kubectl exec test-pod -- nslookup google.com
# 3. Check network policies
kubectl get networkpolicy -A
# 4. Check node networking
kubectl get nodes -o wide
Solutions¶
NetworkPolicy blocking egress
Scenario 3: Service ClusterIP Not Working¶
Problem¶
$ kubectl exec test-pod -- curl http://my-service:80
curl: (7) Failed to connect to my-service port 80
Diagnosis Steps¶
# 1. Check service
kubectl get svc my-service -o wide
# 2. Check endpoints
kubectl get endpoints my-service
# 3. Check kube-proxy
kubectl get pods -n kube-system -l k8s-app=kube-proxy
# 4. Check iptables rules
sudo iptables -t nat -L KUBE-SERVICES | grep my-service
Solutions¶
No endpoints
kube-proxy not running
Scenario 4: Ingress Not Routing Traffic¶
Problem¶
Diagnosis Steps¶
# 1. Check Ingress resource
kubectl get ingress myapp-ingress -o yaml
# 2. Check Ingress controller pods
kubectl get pods -n ingress-nginx
# 3. Check Ingress controller logs
kubectl logs -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx
# 4. Check backend service
kubectl get svc myapp-service
kubectl get endpoints myapp-service
Solutions¶
Backend service not found
Wrong port configuration
Scenario 5: CNI Plugin Issues¶
Problem¶
Pods stuck in ContainerCreating, network not available
Diagnosis Steps¶
# 1. Check CNI pods
kubectl get pods -n kube-system | grep -E "calico|flannel|weave|cilium"
# 2. Check CNI configuration
ls /etc/cni/net.d/
# 3. Check kubelet logs for CNI errors
sudo journalctl -u kubelet | grep -i cni
Solutions¶
CNI not installed
CNI pods crashing
Network Debugging Commands¶
# Test DNS
kubectl run dns-test --image=busybox --rm -it --restart=Never -- nslookup kubernetes
# Test connectivity
kubectl run curl-test --image=curlimages/curl --rm -it --restart=Never -- curl -v http://service:port
# Check pod network
kubectl exec pod-name -- ip addr
kubectl exec pod-name -- ip route
# Check service endpoints
kubectl get endpoints service-name
# Debug with netshoot
kubectl run netshoot --image=nicolaka/netshoot --rm -it --restart=Never -- bash