Sub topic 15
A layered workflow for connectivity problems
This chapter assumes you know the earlier chapters: label selectors, Services, EndpointSlices, cluster DNS, and NetworkPolicy. It also assumes you can use kubectl get, describe, logs, and exec. Here you combine them into one fixed order of checks.
Why order matters
A request passes through several layers: DNS, the Service, its endpoints, and the backend Pod. A failure at one layer looks like a failure at the next. A "connection refused" can come from a wrong targetPort, a stopped container, or a missing endpoint. Test the layers from the client's side, starting at the top, and stop at the first one that fails.
The five checks
Run the first check from inside the cluster, because that is where your application runs. A test from your laptop can pass or fail for unrelated reasons.
kubectl run tmp-debug --rm -it --restart=Never --image=busybox:1.36 -- sh
# inside the Pod:
nslookup web.default.svc.cluster.local
wget -qO- http://web.default.svc.cluster.local:8080- DNS. If
nslookupfails, check/etc/resolv.confin the Pod, then the CoreDNS Pods and logs inkube-system. If the namespace has a default-deny egress policy, confirm that DNS on port 53 is allowed. - Service. Run
kubectl get service web -o wide. Check the namespace in the name you use. Check thatportis the number clients call and thattargetPortis where the container listens. - Endpoints. List the EndpointSlices and compare them with the Pods.
``bash kubectl get endpointslices -l kubernetes.io/service-name=web kubectl get pods -l app=web -o wide ``
If there are no endpoints, either the selector matches no Pod labels or the matching Pods are not ready. The READY column and the readiness probe tell you which.
- Pod directly. Take a Pod IP from the
-o wideoutput and request it on the container port. If this fails, the problem is in the application or the container port, not the Service. - Service IP. If the Pod IP works but the Service name or IP does not, look at what sits between them. Check NetworkPolicies that select the backend or the client, the CNI plugin, and kube-proxy.
Interpreting results
| Symptom | Likely layer | First command |
|---|---|---|
| `bad address` or `NXDOMAIN` | DNS or wrong name | `cat /etc/resolv.conf`, then check CoreDNS |
| Name resolves, connection times out | Endpoints or NetworkPolicy | `kubectl get endpointslices` |
| Name resolves, connection refused | Port mapping | `kubectl describe service web` |
| Works by Pod IP, fails by Service | kube-proxy or policy | `kubectl get networkpolicy` |
Change one thing at a time
Fix the first failing layer, then run the whole sequence again. A fix at layer 3 can expose a port problem at layer 4. Several layers can also be broken at once, and only a full re-run shows that.
Exercise
From a debug Pod, nslookup web.default.svc.cluster.local returns the Service's cluster IP. wget to port 8080 then hangs until it times out. kubectl get endpointslices -l kubernetes.io/service-name=web shows no endpoints. Which layer is failing, and what do you check next?
Show answer
DNS and the Service object are fine, so the failure is at the endpoints layer. A hang with no endpoints means the Service has no ready backends. Compare the Service selector with the Pod labels using kubectl get pods -l app=web. Then check whether the matching Pods are Ready, since a failing readiness probe removes a Pod from the endpoints.