Sub topic 6
How selectors become EndpointSlices
This chapter assumes you know Pods, labels, and the web Deployment and web ClusterIP Service from earlier chapters. It explains how the Service's selector turns into a list of Pod addresses that the cluster can route to.
The Service does not hold the Pod list
A Service stores only a selector and ports. The list of backing Pod IPs lives in separate objects called EndpointSlices. The EndpointSlice controller, which runs in the control plane, watches Services and Pods. When it finds a Service with a selector, it does three things:
- It finds every Pod in the same namespace whose labels match the selector.
- It writes the Pod IPs into one or more EndpointSlice objects.
- It updates those slices as Pods are created, deleted, or change state.
kube-proxy and CoreDNS read the slices. They never evaluate the selector themselves.
Inspecting the slices
The slices carry the label kubernetes.io/service-name, so you can list them by Service name:
kubectl get service web
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl get endpointslices -l kubernetes.io/service-name=web -o yamlThe first listing looks like this. The suffix on the name is random.
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
web-x7k2q IPv4 80 10.244.1.5,10.244.2.8,10.244.1.9 4mIn the YAML, each entry under endpoints has the Pod's addresses, a conditions block (ready, serving, terminating), a targetRef pointing to the Pod, and the nodeName. The ports section holds the result of resolving targetPort. In the web Service, targetPort: http is looked up by name in each Pod, so Pods can use different numbers for the same named port and still be served by one Service.
Limits and details
- A slice holds up to 100 endpoints by default. A Service with 250 Pods gets three slices.
- A Service can have slices for IPv4, IPv6, or both, with one slice set per address type.
- The older
Endpointsobject still exists for compatibility, but it is deprecated. It is also truncated at 1000 addresses, so use EndpointSlices when you inspect or build tooling. - Pods that are not ready still appear in a slice, with
ready: false. Consumers skip them. The next chapter covers this.
Services without selectors
If a Service has no selector, the controller creates nothing. You then write the EndpointSlice yourself, with the kubernetes.io/service-name label set to the Service name. This lets a Service point at an IP outside the cluster, such as a database. If a Service you expect to work has no slices, check its selector first.
Exercise
You run kubectl get endpointslices -l kubernetes.io/service-name=web and get "No resources found", but the Deployment shows 3/3 Pods running. Name two likely causes.
Show answer
The Service selector does not match the Pod labels (for example a typo or a different label key), or the Service and Pods are in different namespaces. Compare kubectl get service web -o yaml with kubectl get pods --show-labels. Also check that the Service has a selector at all, since selector-less Services get no automatic slices.