Sub topic 6
Reading Endpoints and EndpointSlices
This chapter assumes you can use kubectl get, describe, and logs. It also assumes you know how labels and selectors work, and that you have the web Deployment and Service from the earlier chapters running. That Service has port: 8080 and targetPort: 80.
What endpoints are
A Service has a virtual IP, but it has no backends of its own. The EndpointSlice controller in the control plane watches Pods that match the Service selector. It writes their IPs and ports into EndpointSlice objects. kube-proxy reads those objects to program traffic rules on each node. If a Service has no endpoints, there is nowhere to send the traffic.
The older Endpoints object still exists, but recent Kubernetes versions deprecate it. It also truncates the list at 1000 addresses. EndpointSlices hold up to 100 endpoints each by default and a Service can have many slices. Read EndpointSlices first.
Checking a Service for endpoints
kubectl get service web -o wide
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl get pods -l app=web -o wide
kubectl describe service webA healthy result looks like this:
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
web-x7k2p IPv4 80 10.244.1.12,10.244.2.7 5mTwo details matter here. The PORTS column shows the resolved target port (80), not the Service port (8080). The ENDPOINTS addresses should match the IPs in the kubectl get pods -o wide output. The describe service output has an Endpoints: line that lists ready addresses with their ports.
Reading conditions
The table view hides per-endpoint state. To see it, read the YAML:
kubectl get endpointslices -l kubernetes.io/service-name=web -o yamlEach endpoint has a conditions block:
ready: the Pod passes its readiness probe and receives normal traffic.serving: the Pod is able to serve, even while it is shutting down.terminating: the Pod is being deleted.
A Pod that fails its readiness probe stays in the list with ready: false. kube-proxy does not send normal traffic to it.
Finding why endpoints are missing
| Observation | Likely cause | Confirm with |
|---|---|---|
| Slice exists with no endpoints, no Pods listed | Selector does not match any Pod labels | `kubectl get pods -l app=web` |
| Pods exist but are `0/1 Ready` | Readiness probe failing | `kubectl describe pod` events |
| Pods are Ready but the slice is empty | Pods are in a different namespace | `kubectl get pods -A --show-labels` |
| Endpoints exist but requests fail | `targetPort` does not match the listening port | `kubectl get endpointslices -o yaml` |
To test the selector failure, change the Service selector to app: webb and apply it. The Service stays, but the slice loses its addresses. Restoring the selector brings them back within seconds.
Practice
Exercise
kubectl get pods -l app=web shows two Pods with 0/1 in the READY column. What does the EndpointSlice for the web Service contain, and where do you look next?
Show answer
The Pods' endpoints appear with ready: false, or the slice has no ready addresses, so the Service does not route traffic to them. Run kubectl describe pod on one of them and check the readiness probe and its events.
Exercise
The slice shows PORTS 80 but a client calling the Service on port 8080 gets connection refused. Which value do you verify, and against what?
Show answer
Verify that the Service targetPort (80) equals the port the container actually listens on. The slice port comes from targetPort, not from the Service port.