Services, DNS, and kube-proxy
Draft: not yet run against a live cluster. Treat output as representative and check it on yours.
“The service is down” usually means one of four separate things failed: the name didn’t resolve, the Service had no endpoints, the traffic wasn’t forwarded, or the pod didn’t answer on that port. Each one has a different owner and a different fix.
Under the hood
Section titled “Under the hood”-
The Service gets a ClusterIP. The API server allocates it from the cluster’s service CIDR. A headless Service (
clusterIP: None) gets none, and DNS returns the pod IPs directly instead. -
The EndpointSlice controller builds the backend list. It finds pods that match the Service’s
selectorand records their IPs and thetargetPort. Pods that aren’t Ready are marked not ready, and normal traffic skips them. -
kube-proxy programs every node. It watches Services and EndpointSlices and writes forwarding rules (iptables, IPVS, or nftables, depending on your version and configuration) that rewrite the ClusterIP to a pod IP. Some CNIs, such as Cilium in kube-proxy replacement mode, do this with eBPF instead.
-
CoreDNS answers names. Each pod’s
/etc/resolv.confpoints at the cluster DNS Service and lists search domains likeshop.svc.cluster.local,svc.cluster.local, andcluster.local, withndots:5. That’s whywebresolves from inside the same namespace.
Minimal example
Section titled “Minimal example”kubectl create namespace shopkubectl -n shop create deployment web --image=nginx:1.27 --replicas=2kubectl -n shop expose deployment web --port=80 --target-port=80kubectl -n shop get endpointslices -l kubernetes.io/service-name=web -o widekubectl -n shop run probe --rm -it --restart=Never --image=busybox:1.36 -- \ sh -c 'nslookup web; wget -qO- -T 3 http://web | head -3'busybox is used here because it’s small. Its nslookup output differs from dig, and some versions print harmless errors about search domains, so judge by whether an address comes back.
How it breaks
Section titled “How it breaks”Self-check
Section titled “Self-check”A Service exists, but kubectl get endpointslices shows no addresses. Name two causes.
The selector doesn’t match any pod labels, or the matching pods aren’t Ready.
Which component turns a ClusterIP into a pod IP on each node?
kube-proxy (or the CNI’s eBPF replacement), using iptables, IPVS, or nftables rules.
Why can a pod resolve web but a pod in another namespace can't?
Short names resolve through the search domains in /etc/resolv.conf, which start with the pod’s own namespace. From another namespace, use web.shop or the full name.
Endpoints exist, but you get connection refused. Where do you look first?
At the container: the targetPort doesn’t match the listening port, or the process listens only on localhost. Test by connecting to a pod IP directly.
Maps to: CKA: Services and Networking; CKA: Troubleshooting. Check the current exam curriculum, since domain names change between revisions.