Service selectors and EndpointSlices
Follow the selector to the backend
A selector-based Service in book-lab with app: api identifies Pods in that namespace carrying the same label. The Service does not select a Deployment by name or by owner reference. A controller updates EndpointSlices to describe backend addresses and ports. This is asynchronous: a newly changed label may not be reflected immediately.
NAME NAMESPACE APP READYapi-a book-lab api trueapi-b book-lab api falseweb-a book-lab web trueapi-other other-lab api trueOnly api-a and api-b match the Service; api-other is in another namespace. api-b can be represented as an endpoint but is normally not eligible for new traffic while unready.
Read EndpointSlice conditions
EndpointSlice objects use discovery.k8s.io/v1. A Service may have several slices, so inspect all matching slices rather than relying on one object. Endpoint addresses, addressType and ports describe connection targets; readiness and termination conditions help consumers choose targets. In ordinary non-terminating workloads without special publishing settings, prefer ready endpoints. publishNotReadyAddresses changes readiness handling, and draining endpoints have special fallback rules. These advanced exceptions do not apply to the offline cases.
{ "apiVersion": "discovery.k8s.io/v1", "kind": "EndpointSlice", "metadata": { "name": "api-synthetic", "namespace": "book-lab", "labels": { "kubernetes.io/service-name": "api" } }, "addressType": "IPv4", "ports": [ { "name": "http", "protocol": "TCP", "port": 8080 } ], "endpoints": [ { "addresses": [ "192.0.2.21" ], "conditions": { "ready": true, "serving": true, "terminating": false } }, { "addresses": [ "192.0.2.22" ], "conditions": { "ready": false, "serving": false, "terminating": false } } ]}The ready address is 192.0.2.21. The other address remains represented but has ready=false. These documentation IPs are fictional and must not be used for traffic tests. The Service-name label associates the slice with the Service; it is not the Pod selector.
Diagnose empty or unready backends
If a Service has no matching Pods, compare its selector against actual Pod labels in the correct namespace. If Pods match but are not ready, inspect their status and application startup instead of broadening the selector. A ready backend can still fail an application request; inspect the target port and network path. A Service without a selector is a different case: automatic Pod-based EndpointSlice generation is absent, and separately managed endpoints may be needed. Do not edit controller-managed slices to hide a workload problem.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get service/api -o yamlkubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get pods -l app=api --show-labelskubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get endpointslices -l kubernetes.io/service-name=api -o yamlThese commands contact the API and require a separately approved disposable lab, a lab-only kubeconfig, the given context and the namespace. They are static examples, not tested here. Compare every slice and read endpoint conditions in YAML. Do not infer readiness merely from an address appearing in the summary table.
Practice: explain a missing endpoint
Open lab-fixtures/services/pod-inventory.json, selector-cases.json and endpoint-slice.json. For each selector case list matching and ready Pod names separately. Then identify the ready address in the recorded slice and explain why fixing the selector is appropriate only for a selection mismatch. Next: use DNS instead of embedding addresses in applications.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Service selectors and EndpointSlices — knowledge check
Apply the lesson concepts to original offline scenarios.
A Service in book-lab selects app=api. Which inventory Pods match?
A matching non-terminating backend has ready=false under ordinary publishing settings. What is the normal treatment?
What label links a recorded EndpointSlice to Service api?
A Service selects app=api but all intended Pods have app=web. What should you inspect first?
All matching slices contain ready addresses, but requests still fail. What should you check?