Overview and What You Will Learn
Debug Kubernetes networking by testing one layer at a time, starting from the pod's own network interface and moving up to Services, DNS and policy, so you find the broken layer instead of guessing. A pod can be Running and healthy while a CNI fault, an empty Service, a DNS failure or a NetworkPolicy keeps it from talking to anything. In this lab you will use a netshoot debug container and kubectl to isolate each kind of failure.
- Attaching a netshoot debug container to a pod's network namespace
- Diagnosing pods stuck in ContainerCreating because the CNI failed
- Testing pod-to-pod traffic across nodes
- Checking Service endpoints and kube-proxy rules
- Diagnosing CoreDNS and name resolution failures
- Spotting NetworkPolicy drops
Why This Matters in Production
Networking failures are hard to diagnose because the application only reports a timeout or a refused connection. Imagine an order service that calls a risk service and silently falls back to cached data when the call times out. Nothing in the application logs says whether the break is in the CNI, the Service, DNS or a policy, so the team loses hours unless they have a systematic method that proves each layer works before moving to the next.
Core Principles
Five layers can fail independently, and you test them in order, because a fault at a lower layer makes every higher test fail too. The first three tests are about reachability, and DNS and policy are checked once those pass or when the symptoms point to them.
with an IP?}:::q -->|no| L1[CNI setup failing]:::bad A -->|yes| B{Reach a pod
on another node?}:::q B -->|no| L2[CNI overlay or policy]:::bad B -->|yes| C{Reach the
Service ClusterIP?}:::q C -->|no| L3[Endpoints or kube-proxy]:::bad C -->|yes| D[Check DNS and
NetworkPolicy]:::ok classDef q fill:#FFEDD5,color:#1E293B classDef bad fill:#EF4444,color:#FFFFFF classDef ok fill:#10B981,color:#FFFFFF
| Layer | Typical symptom | First tool |
|---|---|---|
| 1. Pod interface and CNI setup | Pod stuck in ContainerCreating with no IP | kubectl describe pod |
| 2. CNI overlay between nodes | Pod has an IP but cannot reach pods on other nodes | CNI pod logs, ping, curl |
| 3. Service routing (endpoints, kube-proxy) | Pod IP works but the Service IP fails | kubectl get endpointslices |
| 4. DNS (CoreDNS) | Service IP works but the name fails | nslookup, CoreDNS logs |
| 5. NetworkPolicy | Timeouts only for some sources or namespaces | kubectl get networkpolicy, Hubble |
A refused connection and a timeout mean different things. A refusal means a packet reached a host that has no listener or a rule that rejects it, and a timeout usually means a packet was dropped on the way.
Detailed Step-by-Step Practical Lab
Step 1 - Attach a netshoot Debug Container
netshoot is a container full of network tools, including curl, dig, nslookup, tcpdump and traceroute. Start a standalone debug pod in the same namespace as the failing service:
kubectl run netshoot --image=nicolaka/netshoot -it --rm -n production -- bashTo see the network exactly as an application pod sees it, attach an ephemeral container to that pod. An ephemeral container always shares the pod's network namespace, so it has the same IP, routes and DNS settings. The --target option names an application container and additionally shares its process namespace:
kubectl debug -it order-service-7d9f8b-xkp2q -n production \ --image=nicolaka/netshoot \ --target=order-service \ -- bashRememberTest from inside the pod's network namespace, not from your laptop. Only a container in the same namespace shows what the application experiences, including its DNS settings and any policy that applies to it.
Step 2 - Layer 1: Does the Pod Have a Network Interface and IP?
kubectl get pod order-service-7d9f8b-xkp2q -n production -o wide # order-service-7d9f8b-xkp2q 0/1 ContainerCreating <none> mumbai-worker-1 kubectl describe pod order-service-7d9f8b-xkp2q -n production# Look in Events for messages such as:# Failed to create pod sandbox: ... failed to set up sandbox container network ...# failed to assign an IP address to containerA pod with no IP means the CNI failed during sandbox setup. Common causes are a CNI pod that is not running on that node, a missing or broken file in /etc/cni/net.d/ on the node, or an exhausted IP pool, which is typical when a cloud CNI runs out of addresses on a small subnet. Check the node and the CNI DaemonSet:
kubectl get nodeskubectl get pods -n kube-system -o wide | grep -E "calico|cilium|flannel|aws-node"kubectl logs -n kube-system CNI-POD-NAME --tail=50If the pod started, check its interface and routes from inside:
ip addr show eth0ip route showStep 3 - Layer 2: Test Pod-to-Pod Traffic Across Nodes
Pick two pods on different nodes and test from a netshoot container in the first:
kubectl get pods -n production -o wide | grep order-service# order-service-7d9f8b-xkp2q 10.244.2.15 mumbai-worker-1# order-service-7d9f8b-mn3lp 10.244.3.22 mumbai-worker-2 # Inside netshoot: test by IP, with TCP as well as ping, since ICMP is often filteredping -c 3 10.244.3.22curl -sS -m 3 http://10.244.3.22:8080/healthIf pods on the same node reach each other but pods on different nodes do not, suspect the overlay. Frequent causes are a cloud firewall or security group that blocks the CNI's tunnel traffic (VXLAN uses UDP 4789, and IP-in-IP uses IP protocol 4), an MTU mismatch, or a CNI agent that is unhealthy on one node. Check the CNI on both nodes:
kubectl get pods -n kube-system -o wide | grep -E "calico|cilium"kubectl logs -n kube-system CNI-POD-ON-FAILING-NODE --tail=100 # Cilium: overall health and an end-to-end testcilium statuscilium connectivity testFor Calico, check BGP or overlay status with calicoctl node status run on the node, if calicoctl is installed there.
Step 4 - Layer 3: Test the Service and Its Endpoints
Test the pod IP directly, then the Service IP. A ClusterIP is virtual and answers only on its ports, so test with curl, not ping:
# Direct pod IP bypasses Service routingcurl -sS -m 3 http://10.244.2.15:8080/health # The Service ClusterIP goes through kube-proxy ruleskubectl get service order-service -n productioncurl -sS -m 3 http://10.96.45.200:8080/healthIf the pod IP works and the Service IP fails, check whether the Service has backends. Modern clusters store them in EndpointSlices, and the older Endpoints API is deprecated:
kubectl get endpointslices -n production -l kubernetes.io/service-name=order-servicekubectl get endpoints order-service -n production# ENDPOINTS shows <none> or an empty list when nothing matches the selectorEmpty endpoints usually mean one of three things. The Service selector does not match the pod labels, the pods are not Ready (a failing readiness probe removes them), or the Service targetPort is wrong. Compare the selector with the labels:
kubectl get service order-service -n production -o jsonpath='{.spec.selector}'kubectl get pods -n production --show-labels | grep order-service# app=orders-service in the pod versus app=order-service in the Service: a typoA Service with no endpoints makes kube-proxy reject connections, so you see "Connection refused" instead of a timeout. If endpoints are correct and the ClusterIP still fails, check that kube-proxy ran and programmed rules on the node. The exact command depends on the proxy mode:
kubectl get pods -n kube-system -l k8s-app=kube-proxykubectl logs -n kube-system KUBE-PROXY-POD | grep -i error # On the node, for iptables modesudo iptables -t nat -L KUBE-SERVICES -n | grep 10.96.45.200Some clusters, such as Cilium with kube-proxy replacement, do not run kube-proxy at all, and others use IPVS or nftables mode, so check which mode your cluster uses first.
TipRestarting the kube-proxy pod on one node forces a rules resync and can fix stale rules, but do it only after you have confirmed the endpoints are correct, so you are not hiding the real cause.
Step 5 - Layer 4: Diagnose DNS
Test names step by step from netshoot:
# 1. The short name resolves only inside the same namespacenslookup order-service # 2. The fully qualified name works from any namespacenslookup order-service.production.svc.cluster.local # 3. Read the pod's DNS settingscat /etc/resolv.conf# nameserver 10.96.0.10# search production.svc.cluster.local svc.cluster.local cluster.local# options ndots:5 # 4. Is external resolution broken too?nslookup example.comIf short names fail but the fully qualified name works, the pod is probably in a different namespace than the Service. If the Service name works but external names fail with SERVFAIL, CoreDNS cannot reach its upstream resolver. Check CoreDNS:
kubectl get pods -n kube-system -l k8s-app=kube-dnskubectl logs -n kube-system -l k8s-app=kube-dns --tail=100kubectl get endpointslices -n kube-system -l kubernetes.io/service-name=kube-dnskubectl get configmap coredns -n kube-system -o yamlBy default CoreDNS forwards external queries to the node's resolver (forward . /etc/resolv.conf). If the nodes cannot reach their resolver, or a firewall blocks it, change the forward line to a resolver your network allows, such as the VPC or datacenter resolver, rather than a public one your organization may prohibit:
kubectl edit configmap coredns -n kube-system# Change the forward line, for example: forward . 10.0.0.2 kubectl rollout restart deployment/coredns -n kube-systemAlso check that NetworkPolicies are not blocking DNS. A default-deny egress policy without a DNS rule is one of the most common causes of cluster-wide name failures in a single namespace.
Step 6 - Layer 5: Look for NetworkPolicy Drops
kubectl get networkpolicy -n production -o widekubectl describe networkpolicy POLICY-NAME -n productionThe classic symptom is that a pod IP works from one namespace and times out from another. Both the client's egress policy and the server's ingress policy must allow the connection. On Cilium, Hubble shows dropped packets and the reason:
hubble observe --namespace production --verdict DROPPED --last 100On Calico, review the policies with calicoctl get networkpolicy -o wide and check its flow logs if enabled. Plain Kubernetes gives no log of policy drops, which is why a flow-observability tool is worth having.
SecurityThe first NetworkPolicy you add to a namespace can instantly cut off every flow you did not list. Add allow rules for each legitimate path, including DNS and monitoring, in the same change.
Step 7 - Run a Connectivity Matrix
Check every important path in one run, so you can compare results before and after a change:
kubectl run connectivity-test --image=nicolaka/netshoot -n production \ --restart=Never -- sh -c 'for url in http://order-service:8080/health \ http://payments-service.payments-production.svc.cluster.local:4000/health; do code=$(curl -s -m 3 -o /dev/null -w "%{http_code}" "$url") echo "$url -> $code"donenslookup example.com > /dev/null && echo "external DNS ok" || echo "external DNS FAILED"' kubectl logs connectivity-test -n productionkubectl delete pod connectivity-test -n productionProduction Best Practices & Common Pitfalls
Common MistakeDiagnosing a network problem from application logs. They report "timeout" or "connection refused" and cannot tell you which layer failed. Use a debug container in the pod's network namespace and test each layer in order.
TipKeep a netshoot image mirrored in your own registry, and know how your cluster allows
kubectl debug. In a real incident you do not want to wait on an image pull or a missing permission.
RememberDebug from the bottom up. If a pod has no IP, DNS tests are meaningless, and if the pod IP is unreachable, the Service and DNS cannot work.
- Use Hubble or an equivalent on production clusters. Policy debugging without drop visibility is guesswork, and the visibility pays for itself on the first incident.
- Alert on CoreDNS SERVFAIL responses. Watch
coredns_dns_responses_totalwith thercode="SERVFAIL"label, since a spike points at an upstream DNS failure that breaks service discovery across the cluster. - Label namespaces predictably. Rely on the automatic
kubernetes.io/metadata.namelabel for namespace selectors. - Check node and CNI health before blaming the app. A single unhealthy CNI agent breaks only the pods on its node, which looks like a flaky service.
- Treat packet capture as a controlled action. Running
tcpdumpon a production node can expose sensitive traffic, so follow your organization's approval and logging process.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
kubectl run netshoot --image=nicolaka/netshoot -it --rm -n NS -- bash |
Start a standalone network debug pod |
kubectl debug -it POD --image=nicolaka/netshoot --target=CONTAINER -n NS -- bash |
Attach a debug container to a pod's network |
kubectl get endpointslices -n NS -l kubernetes.io/service-name=SVC |
Check a Service's backends |
kubectl get networkpolicy -n NS -o wide |
List policies in a namespace |
kubectl get pods -n kube-system -l k8s-app=kube-dns |
Check CoreDNS pod health |
kubectl logs -n kube-system -l k8s-app=kube-dns |
Read CoreDNS logs |
nslookup SVC.NS.svc.cluster.local |
Test DNS from inside a pod |
curl -sS -m 3 http://CLUSTERIP:PORT/path |
Test a Service IP and bypass DNS |
kubectl get pods -n NS -o wide |
Show pod IPs and their nodes |
hubble observe --verdict DROPPED |
Show packets dropped by policy on Cilium |