Skip to content
LF Cert Trainer

Lesson 142 · Section 12: Troubleshooting

Lesson 142: Network troubleshooting: Pod network, Services, DNS and policies

A layered way to find why traffic does not flow in a cluster: test Pod to Pod first (the CNI plugin), then Pod to Service (kube-proxy and endpoints), then names (CoreDNS), then NetworkPolicies, with one test command and one usual fault for each layer. · 24 min read · 3 min video

1/10Network troubleshooting
0:00 / 2:55

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why network faults need layers

Most failures announce themselves: a Pod in CrashLoopBackOff, an event, an error line in a log. Network faults usually do not. A request simply times out, and every component involved may still look Running. If you start by reading CoreDNS logs when the real fault is a missing CNI plugin, you can spend a long time finding nothing.

Cluster networking is built in layers, and each layer depends on the ones below. Testing them bottom up, with one command per layer, turns "the network is broken" into "this component is broken".

Four layers

Test the network in four layers, bottom firstthenthenthenPod to Pod IPCNI pluginPod to Service IPkube-proxy, endpointsPod to nameCoreDNSAllowed?NetworkPolicy
Test the network in four layers, bottom first. Each layer depends on the ones below it. If Pod IPs cannot reach each other, Services and DNS cannot work either, so test Pod to Pod first.

Parts:

  • Pod to Pod IP (CNI plugin)
  • Pod to Service IP (kube-proxy, endpoints)
  • Pod to name (CoreDNS)
  • Allowed? (NetworkPolicy)

Connections:

  • Pod to Pod IP to Pod to Service IP: then
  • Pod to Service IP to Pod to name: then
  • Pod to name to Allowed?: then
LayerTest (from a busybox Pod)Built byUsual faults
Pod to Podwget -qO- -T 2 http://<pod-ip>:<port>, ping <pod-ip>The CNI plugin (Calico, Cilium, Flannel...) and its DaemonSetNo CNI installed (nodes NotReady, Pods stuck ContainerCreating), CNI Pod crash looping on one node, Pod CIDR mismatch
Pod to Service IPwget -qO- -T 2 http://<cluster-ip>:<port>kube-proxy (DaemonSet), the Service and its endpointsNo endpoints (selector, readiness), wrong targetPort, kube-proxy crash looping
Pod to namenslookup <svc>.<ns>, nslookup kubernetes.defaultCoreDNS (Deployment), the kube-dns Service, the kubelet's clusterDNSCoreDNS down, kube-dns with no endpoints, broken Corefile, wrong clusterDNS in the kubelet config
Allowed?The same test from a Pod with different labelsNetworkPolicies, enforced by the CNI pluginA default deny, a selector that misses the client, egress that blocks DNS

Run all tests from a single throwaway Pod. Put it in the same namespace as the client in the task, so namespace policies apply to it in the same way:

kubectl -n shop run tmp --rm -it --restart=Never --image=busybox:1.36 -- sh
# then, inside:
wget -qO- -T 2 http://10.244.2.9:8080        # a backend Pod IP (kubectl get pods -o wide)
wget -qO- -T 2 http://10.96.80.11:80         # the Service ClusterIP
wget -qO- -T 2 http://web-svc.shop:80        # the Service name
nc -zv -w 2 mysql-svc.shop 3306              # a TCP port, for non-HTTP services

Layer 1: Pod to Pod (the CNI plugin)

Kubernetes requires that every Pod can reach every other Pod by IP, without NAT, on any node. Kubernetes itself does not implement that: the CNI plugin does. The kubelet calls it to give each new Pod an interface and an IP.

SymptomLikely causeCheck
All nodes NotReady, message NetworkPluginNotReady / cni plugin not initializedNo CNI plugin installedls /etc/cni/net.d/ on a node is empty; no CNI Pods in kube-system (or its own namespace)
New Pods stuck ContainerCreating, event FailedCreatePodSandBoxThe CNI plugin cannot set up the Pod on that nodekubectl describe pod; the CNI Pod on that node; journalctl -u kubelet
Pods on one node cannot reach Pods on other nodesThe CNI agent on that node is broken, or a firewall between nodeskubectl -n kube-system get pods -o wide filtered to that node; compare with a working node
Pods get IPs from the wrong rangeThe CNI's Pod CIDR does not match the cluster's --cluster-cidr / podSubnetThe CNI config vs kubectl cluster-info dump | grep -m1 cluster-cidr
kubectl get pods -A -o wide | grep -E 'calico|cilium|flannel|weave'
ls /etc/cni/net.d/ /opt/cni/bin/          # on the node

Installing or fixing the CNI is usually a single kubectl apply of the plugin's manifest, with the Pod CIDR the cluster was built with.

Layer 2: Pod to Service (kube-proxy and endpoints)

What turns a Service IP into a Pod IPto svc IPDNATwriteswatchesClient Pod10.244.1.5Node rulesKUBE-SERVICESBackend Pod10.244.2.9:8080kube-proxyDaemonSetAPI serverServices, slices
What turns a Service IP into a Pod IP. No process listens on a ClusterIP. kube-proxy on every node writes rules (iptables, IPVS or nftables) that rewrite the Service IP to one of the endpoint Pod IPs. If kube-proxy is down, new Services and endpoint changes never reach the rules.

Parts:

  • Client Pod (10.244.1.5)
  • Node rules (KUBE-SERVICES)
  • Backend Pod (10.244.2.9:8080)
  • kube-proxy (DaemonSet)
  • API server (Services, slices)

Connections:

  • Client Pod to Node rules: to svc IP
  • Node rules to Backend Pod: DNAT
  • kube-proxy to Node rules: writes
  • kube-proxy to API server: watches

No process listens on a ClusterIP. kube-proxy, a DaemonSet on every node, watches Services and EndpointSlices and writes packet-filter rules (iptables by default, or IPVS, or nftables) that rewrite the Service address to one of the endpoint Pod IPs.

Check in this order:

kubectl -n shop get svc web-svc                                   # ClusterIP and port
kubectl -n shop get endpoints web-svc                             # any addresses?
kubectl -n kube-system get pods -l k8s-app=kube-proxy -o wide     # running on every node?
kubectl -n kube-system logs -l k8s-app=kube-proxy --tail=5 --prefix

If there are no endpoints, the fault is the selector or Pod readiness (see the application failure lesson). If there are endpoints and the Pod IP test worked, but the Service IP test fails, look at kube-proxy.

Under the hood · Looking at the rules kube-proxy writes

In iptables mode, every Service gets a chain. On a node you can see whether your Service made it into the rules:

iptables-save | grep 'shop/web-svc'
-A KUBE-SERVICES -d 10.96.80.11/32 -p tcp -m comment --comment "shop/web-svc cluster IP" -m tcp --dport 80 -j KUBE-SVC-X7Q3...
-A KUBE-SVC-X7Q3... -m comment --comment "shop/web-svc -> 10.244.2.9:8080" -j KUBE-SEP-...

No lines at all for a Service that exists means kube-proxy on that node is not running or not syncing. Lines that point at old Pod IPs mean it stopped syncing some time ago. The mode kube-proxy uses is in its ConfigMap (kubectl -n kube-system get cm kube-proxy -o yaml | grep mode); with IPVS, use ipvsadm -Ln instead. Some CNI plugins (Cilium, for example) replace kube-proxy entirely, in which case there is no kube-proxy DaemonSet at all and that is normal.

Example · kube-proxy crash loops after a change

kubectl -n kube-system get pods -l k8s-app=kube-proxy
kubectl -n kube-system logs kube-proxy-4xk2p
kube-proxy-4xk2p   0/1   CrashLoopBackOff   6
"command failed" err="failed complete: open /var/lib/kube-proxy/configuration.conf: no such file or directory"

The kube-proxy Pods mount the kube-proxy ConfigMap at /var/lib/kube-proxy/, and the DaemonSet passes --config=/var/lib/kube-proxy/config.conf. Compare the flag with the key in the ConfigMap:

kubectl -n kube-system get ds kube-proxy -o yaml | grep -A3 -- '- command'
kubectl -n kube-system get cm kube-proxy -o jsonpath='{.data}' | head -c 200; echo

Fix whichever side is wrong (here the DaemonSet's --config path), then roll it out to every node:

kubectl -n kube-system edit ds kube-proxy        # --config=/var/lib/kube-proxy/config.conf
kubectl -n kube-system rollout status ds kube-proxy

Layer 3: names (CoreDNS)

The path of one DNS lookupport 53endpointswatchesforwardPod/etc/resolv.confService kube-dns10.96.0.10:53CoreDNS PodsCorefileAPI serverServices, slicesUpstream DNS/etc/resolv.conf
The path of one DNS lookup. The Pod's resolv.conf names the kube-dns Service. That Service must have CoreDNS endpoints, and CoreDNS must be able to read Services from the API server and forward outside names upstream.

Parts:

  • Pod (/etc/resolv.conf)
  • Service kube-dns (10.96.0.10:53)
  • CoreDNS Pods (Corefile)
  • API server (Services, slices)
  • Upstream DNS (/etc/resolv.conf)

Connections:

  • Pod to Service kube-dns: port 53
  • Service kube-dns to CoreDNS Pods: endpoints
  • CoreDNS Pods to API server: watches
  • CoreDNS Pods to Upstream DNS: forward
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide       # CoreDNS Pods keep this old label
kubectl -n kube-system get svc kube-dns                           # usually 10.96.0.10
kubectl -n kube-system get endpoints kube-dns                     # CoreDNS Pod IPs, port 53
kubectl -n kube-system logs -l k8s-app=kube-dns --tail=20 --prefix
kubectl -n kube-system get cm coredns -o jsonpath='{.data.Corefile}'

From a test Pod:

cat /etc/resolv.conf                       # nameserver 10.96.0.10, search shop.svc.cluster.local svc.cluster.local ...
nslookup kubernetes.default                # the most basic in-cluster name
nslookup web-svc.shop
nslookup kubernetes.io                     # an outside name: tests the forward plugin
What you seeWhere to look
nslookup times out, connection timed out; no servers could be reachedCoreDNS Pods down or not ready; kube-dns has no endpoints (selector); a NetworkPolicy blocks port 53
nameserver in the Pod's resolv.conf is not the kube-dns ClusterIPThe kubelet's clusterDNS in /var/lib/kubelet/config.yaml on that node
Cluster names work, outside names failThe forward line of the Corefile, or the node's own /etc/resolv.conf
CoreDNS crash loops, plugin/loop: Loop ... detectedThe node's resolv.conf points at a local resolver (127.0.0.53): forward to a real upstream
CoreDNS crash loops after an editA typo in the Corefile; the logs give the line
NXDOMAIN for a Service that existsWrong namespace in the name, or a typo; short names only work in the same namespace

Example · The kube-dns Service lost its endpoints

Every name lookup times out, yet both CoreDNS Pods are 1/1 Running.

kubectl -n kube-system get endpoints kube-dns
kubectl -n kube-system get svc kube-dns -o jsonpath='{.spec.selector}'; echo
kubectl -n kube-system get pods -l k8s-app=kube-dns --show-labels | head -n 2
kube-dns   <none>
{"k8s-app":"core-dns"}
coredns-6f6b679f8f-7lq2m   1/1   Running   k8s-app=kube-dns,pod-template-hash=6f6b679f8f

The selector was changed to core-dns; the Pods carry kube-dns. Restore it and test:

kubectl -n kube-system patch svc kube-dns -p '{"spec":{"selector":{"k8s-app":"kube-dns"}}}'
kubectl -n kube-system get endpoints kube-dns
kubectl run tmp --rm -it --restart=Never --image=busybox:1.36 -- nslookup kubernetes.default

Layer 4: is the traffic allowed?

If the Pod IP, the Service IP and the name all work from your test Pod but the real client still times out, look for a NetworkPolicy. Once any policy selects a Pod for a direction (ingress or egress), only traffic that some policy allows in that direction gets through.

kubectl get netpol -A
kubectl -n shop describe netpol
kubectl -n shop get pods --show-labels                 # does the client match the from: selector?
kubectl get ns --show-labels                           # namespaceSelector matches namespace labels

Example · An egress policy that also blocks DNS

After a policy restricting egress from web was added, web cannot reach mysql-svc by name, although the policy allows port 3306 to the database:

spec:
  podSelector: { matchLabels: { app: web } }
  policyTypes: [Egress]
  egress:
    - to: [ { podSelector: { matchLabels: { app: mysql } } } ]
      ports: [ { port: 3306 } ]

The name lookup goes to CoreDNS on port 53, and nothing allows that. Add a rule for DNS:

    - to: [ { namespaceSelector: { matchLabels: { kubernetes.io/metadata.name: kube-system } } } ]
      ports: [ { port: 53, protocol: UDP }, { port: 53, protocol: TCP } ]

Policies only work if the CNI plugin enforces them. Flannel alone does not: with it, a policy is accepted and silently ignored.

Tricks

Common mistakes

  • Pinging a Service. ClusterIPs only answer on their ports.
  • Testing from the wrong namespace. Short names resolve only in the same namespace, and namespace-scoped policies treat your test Pod differently.
  • Restarting CoreDNS for a selector problem. Healthy CoreDNS Pods behind a Service with no endpoints are unreachable. get endpoints kube-dns first.
  • Forgetting DNS in egress policies. Restricting egress without allowing port 53 breaks every name.
  • Editing a kube-proxy Pod. It belongs to a DaemonSet. Edit the DaemonSet or the ConfigMap, then rollout restart.
  • Assuming the CNI enforces policies. Without enforcement, a policy you write "works" in YAML and does nothing.

Recap

  • Test bottom up from one busybox Pod: Pod IP, Service IP, Service name, then from a client with other labels.
  • Pod to Pod is the CNI plugin: nodes NotReady with NetworkPluginNotReady, sandboxes that fail.
  • Service IPs are endpoints plus kube-proxy: get endpoints, kube-proxy Pods and their logs, iptables-save.
  • Names are CoreDNS: its Pods, the kube-dns endpoints, the Corefile, the Pod's resolv.conf.
  • Timeouts with every component healthy are usually NetworkPolicies, including egress that blocks DNS.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Service names stopped resolving across the cluster, and in one namespace they still fail after that is fixed. Test layer by layer, repair cluster DNS, then open exactly the traffic a locked-down namespace needs for names.

    Fix · Level 2 · standard · target 20 min

  • A cluster with three faults at once, one in a worker node, one in the control plane and one in cluster networking, picked at random for each session. Find them with the troubleshooting method, repair them, and ship a release through the repaired cluster.

    Fix · Level 3 · challenge · target 40 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.