Skip to content
Visual explainer 3h to learn 4 steps

Service & network troubleshooting

Trace a failed request from Service to endpoints to Pod to DNS.

By Invicly Tech, , in Kubernetes Administrator (CKA). About 10 minutes to read.

Topic 29 of 33

In short

When a request fails, trace it hop by hop: DNS name, Service, endpoints, Pod port and the app itself. Most failures are a selector mismatch, a wrong targetPort, a NetworkPolicy, or broken kube-proxy or CoreDNS. A temporary debug Pod lets you test each hop from inside the cluster.

Explained simply

A request inside Kubernetes passes through several stops: the name is turned into an IP by DNS, the Service IP is turned into a Pod IP by kube-proxy rules, the packet travels over the Pod network, any NetworkPolicy checks it, and finally the app must be listening on the right port.

When something fails, testing the whole chain at once tells you little. Testing one stop at a time tells you exactly where it breaks. It is like finding a leak in a pipe: you check each joint in turn.

Always test from inside the cluster. Your laptop cannot reach ClusterIPs or Pod IPs, so a failed curl from outside proves nothing. Start a temporary Pod with network tools and test from there, ideally from the same namespace as the real client.

The good news: most problems are small configuration mistakes, like a Service selector that does not match, a wrong port number, or a forgotten DNS rule in a NetworkPolicy. Once you find the right stop, the fix is usually one line.

Press Play on a diagram to walk through it one step at a time.

FlowTrace a failed request
  1. 1
    DNS

    nslookup the Service name from a debug Pod.

  2. 2
    Service

    Check ports, targetPort and selector.

  3. 3
    Endpoints

    EndpointSlice must list Ready Pod IPs.

  4. 4
    Pod directly

    curl PodIP:port to bypass the Service.

  5. 5
    Policies and proxy

    Check NetworkPolicies and kube-proxy Pods.

SequenceTesting a failing call hop by hop
Debug Pod
CoreDNS
Service (kube-proxy)
Backend Pod
  1. 1nslookup api.prod: gets ClusterIP?
    Debug Pod to CoreDNS: nslookup api.prod: gets ClusterIP?
  2. 2curl ClusterIP:80: answer?
    Debug Pod to Service (kube-proxy): curl ClusterIP:80: answer?
  3. 3curl PodIP:8080 directly: answer?
    Debug Pod to Backend Pod: curl PodIP:8080 directly: answer?
  4. 4exec: wget localhost:8080 inside the Pod
    Backend Pod to Backend Pod: exec: wget localhost:8080 inside the Pod
  5. 5First hop that fails is the culprit
    Backend Pod to Debug Pod: First hop that fails is the culprit

In depth

Reading the error message correctly

The error type already narrows down the stop. Could not resolve host or bad address means DNS: the name is wrong, in another namespace, or CoreDNS is unreachable. Connection refused means a packet arrived but nothing was listening on that port: a wrong targetPort, an app listening on a different port, or a Service with no endpoints on some kube-proxy modes. A timeout means packets disappeared: a NetworkPolicy dropping them, a broken Pod network between nodes, or a Pod that does not exist at that IP.

Use short timeouts so tests fail fast: curl -m 3, wget -T 3 or nc -w 3. Test the IP and the name separately; if the IP works and the name does not, the problem is DNS, nothing else.

MapError type to likely cause
Request failed
  • Name not resolved
    • Wrong name or namespace
    • CoreDNS down or 0 replicas
    • Egress policy blocks port 53
  • Connection refused
    • Wrong targetPort
    • App listens on another port
    • App bound to 127.0.0.1 only
  • Timeout
    • NetworkPolicy drops it
    • Cross-node Pod network broken
    • kube-proxy rules missing

Checking each hop with one command

DNS: nslookup SERVICE.NAMESPACE from the debug Pod. Service: kubectl get svc NAME -o wide shows the selector and ports. Endpoints: kubectl get endpointslices -l kubernetes.io/service-name=NAME must list Ready Pod IPs. Pod: curl POD_IP:TARGET_PORT from the debug Pod skips the Service entirely. App: kubectl exec POD -- wget -qO- localhost:PORT tests from inside the Pod itself, which skips the network entirely.

If localhost works but the Pod IP does not, the app is probably listening on 127.0.0.1 instead of 0.0.0.0. If the Pod IP works but the Service does not, look at selector, ports and kube-proxy. If the Pod IP fails only from other nodes, look at the CNI. If it fails only from some namespaces, look at NetworkPolicies.

  • kubectl exec POD -- netstat -tlnp (or ss -tlnp) shows listening ports if the image has it
  • kubectl get netpol -n NS before anything else when traffic times out
  • kubectl port-forward skips kube-proxy and policies: good for testing the app only

kube-proxy health

kube-proxy runs as a DaemonSet in kube-system, one Pod per node, and is configured by the kube-proxy ConfigMap (the config.conf key holds mode, clusterCIDR and more). If its Pod on a node is crashing, Services stop working only from Pods on that node, a pattern worth spotting: test from Pods on two different nodes.

Check kubectl -n kube-system get ds kube-proxy for DESIRED equal to READY, then read the logs of the Pod on the bad node. A broken ConfigMap (for example a typo in mode or a wrong kubeconfig path) makes all kube-proxy Pods fail after a restart. After fixing the ConfigMap, run kubectl -n kube-system rollout restart ds kube-proxy. On the node, iptables-save -t nat | grep SERVICE_NAME (or nft list ruleset in nftables mode) proves whether rules exist for the Service.

Debug tools that save time

busybox has nslookup, wget and nc, which covers most tests. For deeper work, an image like nicolaka/netshoot adds curl, dig, tcpdump, ss and more. kubectl run tmp --rm -it --image=... --restart=Never -- sh gives you a throwaway shell that deletes itself on exit.

To test exactly as a real client would, give the debug Pod the same namespace and labels as that client with -n and -l, because NetworkPolicies decide by labels and namespace. For node-level checks, kubectl debug node/NODE -it --image=busybox:1.36 opens a shell in a Pod on that node using the host's network, with the node's filesystem under /host. That lets you test from the node without ssh.

  • kubectl run tmp -n prod -l app=frontend --rm -it --image=busybox:1.36 --restart=Never -- sh
  • kubectl debug node/worker1 -it --image=busybox:1.36
  • dig +short SERVICE.NS.svc.cluster.local from netshoot

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Verify Service selectors and endpoints~45m
  2. 2
    Test connectivity from a debug Pod~45m
  3. 3
    Check kube-proxy and DNS~45m
  4. 4
    Trace a request end to end~45m

Key points

  • If the Pod IP works but the Service does not, suspect selector, ports or kube-proxy.
  • If neither works, check the app, container port and NetworkPolicies.
  • If names fail but IPs work, debug CoreDNS.
  • kube-proxy runs as a DaemonSet in kube-system; check its logs.

Key terms

Tap a card to flip it. 0/4 known

Examples

bash
kubectl run tmp --image=nicolaka/netshoot --rm -it --restart=Never -- bash
# inside the Pod:
nslookup web.prod
curl -s -m 3 web.prod:80
curl -s -m 3 10.244.1.15:8080   # Pod IP directly
exit
kubectl get svc web -n prod -o yaml | grep -A3 selector
kubectl get endpointslices -n prod -l kubernetes.io/service-name=web
kubectl get networkpolicy -n prod
kubectl -n kube-system logs ds/kube-proxy | tail

Service works by Pod IP, not by name

A frontend reports api.prod unreachable. Step 1: from a debug Pod, nslookup api.prod gets the ClusterIP, so DNS is fine. Step 2: curl to the Service times out, but curl to a Pod IP on 8080 works. Step 3: the Service shows targetPort 80, while the app listens on 8080, and the EndpointSlice port says 80. Step 4: patch the targetPort; curl to the Service now works.

bash
kubectl run tmp -n prod --rm -it --image=busybox:1.36 --restart=Never -- sh
  nslookup api.prod                # resolves to 10.96.88.4
  wget -qO- -T 3 http://api.prod  # fails
  wget -qO- -T 3 http://10.244.2.7:8080   # works
  exit
kubectl -n prod get svc api -o jsonpath='{.spec.ports}'; echo
kubectl -n prod patch svc api --type=json \
  -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":8080}]'

All Services broken from one node only

Pods on worker2 cannot reach any Service, while Pods on worker1 can. Step 1: Pod IPs work from worker2, so the Pod network is fine. Step 2: list kube-proxy Pods with -o wide; the one on worker2 is in CrashLoopBackOff. Step 3: its log shows the cause; here the node was missing a kernel module after a reboot. Step 4: fix it and delete the Pod so the DaemonSet recreates it.

bash
kubectl -n kube-system get pods -l k8s-app=kube-proxy -o wide
kubectl -n kube-system logs kube-proxy-x7k2p --previous | tail -5
kubectl -n kube-system get cm kube-proxy -o yaml | grep -E 'mode|clusterCIDR'
# after fixing the cause on the node:
kubectl -n kube-system delete pod kube-proxy-x7k2p
kubectl -n kube-system get pods -l k8s-app=kube-proxy -o wide

Quick reference

  • Not resolved = DNS; connection refused = port or listener; timeout = policy, CNI or proxy
  • Test order: name, Service IP, Pod IP, localhost inside the Pod
  • Works on localhost but not Pod IP: the app listens on 127.0.0.1
  • Broken only from one node: check the kube-proxy and CNI Pods on that node
  • kubectl debug node/NODE -it --image=busybox:1.36 gives a host-network shell
  • Give debug Pods the client's namespace and labels when policies are involved
  • kubectl -n kube-system rollout restart ds kube-proxy after fixing its ConfigMap

Common mistakes

  • Testing from your laptop instead of from inside the cluster.
  • Forgetting that NetworkPolicies can silently drop traffic.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1curl to a Service name says Could not resolve host, but curl to its ClusterIP works. What do you debug?

Question 2

2From inside the Pod, wget localhost:8080 works, but from another Pod, PodIP:8080 is refused. Likely cause?

Question 3

3A connection attempt hangs until it times out. Which cause fits best?

Question 4

4Services fail only from Pods on worker3. What do you check first?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    From a temporary Pod, test DNS, Service IP and one Pod IP for Service web in namespace default, each with a 3 second timeout.

  2. Exercise 2medium

    Service shop in namespace store has no endpoints. Find out why and fix it without changing the Pods.

  3. Exercise 3hard

    Frontend Pods (app=frontend, namespace web) time out calling api.prod:80. DNS works. Find the blocking NetworkPolicy and add the smallest rule that fixes it.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

How do I test if a Kubernetes Service is working?
Start a temporary Pod with kubectl run --rm -it and call the Service by name and by ClusterIP with wget or curl. Then check kubectl get endpointslices for Ready Pod IPs.
Why can I not ping a Service IP?
ClusterIPs are virtual and kube-proxy only forwards the Service's TCP, UDP or SCTP ports, so ICMP ping usually gets no reply. Test the port instead.
What is a good image for network debugging?
busybox covers nslookup, wget and nc. nicolaka/netshoot adds curl, dig, tcpdump and many more tools when you need them.

Go deeper

ShareXLinkedInWhatsApp