Sub topic 18
Troubleshooting Service connectivity
This chapter assumes you know Pods, Deployments, labels, and the Service types from earlier chapters. It also assumes you can read kubectl output and know basic DNS and TCP. The goal is a fixed order of checks that finds the failing layer quickly.
The working model
A request to a Service passes through several layers. Each layer can fail on its own:
- DNS turns the Service name into a ClusterIP.
- kube-proxy on the node rewrites that virtual IP to a Pod IP.
- EndpointSlices decide which Pod IPs are candidates.
- Readiness decides whether a Pod is listed as ready.
- A NetworkPolicy may drop the packet.
- The container must listen on the target port.
Work from the Service toward the Pod and stop at the first layer that looks wrong.
Step 1: Service and endpoints
Run the commands from the earlier examples:
kubectl get service web
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl run tmp --rm -it --image=busybox:1.36 --restart=Never -- nslookup web.default.svc.cluster.localAn EndpointSlice with no addresses is the most common finding. It has two usual causes:
- The Service
selectordoes not match the Pod labels. A typo such asapp: webbselects nothing. - The Pods exist but are not Ready, because the readiness probe fails.
Compare the selector and the labels directly:
kubectl get service web -o jsonpath='{.spec.selector}'
kubectl get pods -l app=web --show-labels
kubectl get pods -l app=webIf the READY column shows 0/1, run kubectl describe pod and read the probe events.
Step 2: Ports
Three port values must line up. port is what clients use on the Service. targetPort is the container port, either a number or a name. If targetPort: http names a port that the Pod does not declare, the Service has no usable target. The container must also listen on that port on 0.0.0.0. An app bound only to 127.0.0.1 refuses connections that arrive on the Pod IP.
Step 3: DNS and namespaces
A short name like web resolves only within the same namespace. From another namespace, use web.default or the full web.default.svc.cluster.local. If lookups fail for every Service, check that the CoreDNS Pods in kube-system are running.
Step 4: Policy and proxy
If DNS and endpoints are correct, test a Pod IP directly from a temporary Pod. If the Pod IP works but the Service IP does not, look at kube-proxy on the node. If both fail, suspect a NetworkPolicy or the CNI plugin.
Quick reference
| Symptom | Likely cause |
|---|---|
| Empty EndpointSlice | Selector mismatch or Pods not Ready |
| `connection refused` | Wrong `targetPort`, or app not listening |
| Timeout | NetworkPolicy, CNI, or kube-proxy problem |
| `NXDOMAIN` or `bad address` | Wrong name or namespace, or CoreDNS down |
Exercise
A Service named api in namespace prod has an empty EndpointSlice, yet kubectl get pods shows three Pods running with the label app=api. What do you check next, and why?
Show answer
Check that the Pods are Ready, not only Running, with kubectl get pods -l app=api and kubectl describe pod. A failing readiness probe removes a Pod from the EndpointSlice. Also confirm the Pods are in the prod namespace, because a Service selects only Pods in its own namespace, and confirm the selector matches the labels exactly.