Skip to main content

Endpoints and EndpointSlices

Stage 2 · Guidance

You will be able to: read an EndpointSlice field by field, predict the ready, serving and terminating conditions of a Pod at each point in its life, explain why the older Endpoints object was replaced, and hand-write an EndpointSlice for a Service that has no selector.

The previous chapter showed kube-proxy turning a list of endpoints into kernel rules. That list is the hinge of the whole Service mechanism. A Service with a correct ClusterIP, correct DNS and healthy Pods still fails if the list is empty, stale, or lists the wrong port. When a Service misbehaves, the EndpointSlice is the first object to read, because it shows what the data path is actually being told.

The idea​

An endpoint is one network destination that can serve a Service: an IP address, a port, and some facts about it (is it ready, which node is it on, which Pod is it). An EndpointSlice is an API object that holds a batch of endpoints for one Service.

Think of it as a duty roster pinned up for the switchboard. The roster says who is on shift and who is about to leave. The switchboard operators (kube-proxy on every node) read it and route calls accordingly. The roster does not answer calls. Where the analogy breaks: there can be several roster pages per Service, and each is a separate object that changes on its own.

ObjectAPIStatus in Kubernetes v1.37
EndpointSlicediscovery.k8s.io/v1The source kube-proxy, DNS and gateways read
Endpointsv1 (core)Still populated for compatibility; deprecated since v1.33. kubectl get endpoints prints a warning

Anatomy of an EndpointSlice​

A slice for Apollo's flight Service with two Pods, one of them still starting:

apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: flight-x7k2p # <service>-<random>
namespace: apollo-airlines-apps
labels:
kubernetes.io/service-name: flight # which Service this belongs to
endpointslice.kubernetes.io/managed-by: endpointslice-controller.k8s.io # who may edit it
ownerReferences:
- {kind: Service, name: flight} # deleted with the Service
addressType: IPv4 # one family per slice
ports:
- name: "" # matches the Service port's name
port: 8081 # the resolved targetPort, not the Service port
protocol: TCP
endpoints:
- addresses: ["10.244.1.6"]
conditions: {ready: true, serving: true, terminating: false}
nodeName: apollo11-worker
targetRef: {kind: Pod, name: flight-6d8f9c-abcde}
- addresses: ["10.244.2.9"]
conditions: {ready: false, serving: false, terminating: false} # readiness probe not passed yet
nodeName: apollo11-worker2
targetRef: {kind: Pod, name: flight-6d8f9c-fghij}
FieldWhat it tells youDebugging use
kubernetes.io/service-name labelThe owning ServiceThe only way to find a Service's slices: -l kubernetes.io/service-name=flight
managed-by labelWhich controller owns itA slice you wrote by hand must use your own value, or the controller deletes it
addressTypeIPv4 or IPv6A dual-stack Service gets one slice per family
ports[].portThe container port the rules DNAT toA wrong number here means a wrong targetPort in the Service
endpoints[].addressesThe Pod IPCompare with kubectl get pods -o wide
endpoints[].conditionsWhether the data path may use itSee the next section
nodeName, zoneWhere it runsUsed by Local traffic policies and topology-aware routing
targetRefThe Pod behind the IPJump from an IP to a Pod name

Note that not-ready Pods are listed, with ready: false. The older kubectl get endpoints view hides them in a separate notReadyAddresses list, which is easy to miss. Pods without an IP yet (still Pending) and Pods that have finished (Succeeded or Failed) are not listed at all.

Conditions through a Pod's life​

The three conditions are set by the EndpointSlice controller from the Pod's state:

  • ready: the data path should send new connections here. True when the Pod's Ready condition is true and the Pod is not terminating.
  • serving: the Pod's readiness probe is passing, regardless of termination. The same as ready, except it stays true while a Pod shuts down.
  • terminating: the Pod has been asked to stop (it has a deletion timestamp).
MomentreadyservingterminatingGets new connections?
Container started, probe not yet passedfalsefalsefalseNo
Readiness passingtruetruefalseYes
Readiness failing (e.g. search's /readyz when flight is down)falsefalsefalseNo
Pod deleted, preStop running, probe still passingfalsetruetrueOnly as a fallback
Containers exitedremovedNo

kube-proxy uses ready endpoints. If a Service has none, it falls back to endpoints that are serving and terminating, so that replacing the last Pod does not refuse connections while the old one finishes. A Service with publishNotReadyAddresses: true (common for headless StatefulSet Services) reports every endpoint as ready regardless of probes.

The terminating stage is why graceful termination works in two directions at once: the endpoint leaves new-connection rotation immediately, while the process keeps serving what it already has.

Why slices replaced Endpoints​

The original Endpoints object held every address of a Service in one object. Every node's kube-proxy watches it, so every change (one Pod becoming ready) re-sent the whole object to every node. For a Service with thousands of Pods in a cluster of thousands of nodes, one rolling update moved gigabytes through the API server. The object was also capped at 1,000 addresses; beyond that it is truncated and annotated endpoints.kubernetes.io/over-capacity: truncated.

EndpointSlices fix this by splitting:

Endpoints (legacy)EndpointSlice
Objects per ServiceOneMany; up to 100 endpoints each by default
One Pod changesWhole list re-sent to every watcherOnly the affected slice
Address familiesMixedOne per slice
Per-endpoint dataIP, Pod, nodeAdds serving, terminating, zone, topology hints
Size limit1,000 addresses, then truncatedNone in practice

The controller does not rebalance slices on every change, to avoid churn. A Service whose Pods were replaced many times can end up with several part-full slices. That is normal.

Who writes slices​

WriterWhenmanaged-by value
EndpointSlice controllerService has a selectorendpointslice-controller.k8s.io
EndpointSlice mirroring controllerService has no selector and you wrote a legacy Endpoints object by handendpointslicemirroring-controller.k8s.io
You, or another controllerService has no selectorAnything else, e.g. staff

A Service with a selector belongs to the controller: hand edits to its slices are overwritten within seconds. A Service without a selector gets no slices at all until someone writes them. That is the supported way to give an in-cluster name to something that is not a Pod: a database on a VM, a service in another cluster, or a target you are migrating towards.

Apollo example​

Every Apollo Service in stages/stage2/k8s/apps/ has a selector, so the controller manages all their slices. Two Stage 2 behaviours are visible only in them:

  • Readiness chains. search's readiness probe calls flight's /readyz. If flight has no ready Pods, search's Pods stay Running but flip to ready: false in search's slice. Nothing restarts; search simply stops receiving traffic.
  • The broken-selector drill in Substage 1 patches identity's selector to app: identity-broken. The slice empties, kube-proxy installs a REJECT rule, and calls fail while the identity Pod is perfectly healthy. No event is emitted: an empty slice is a valid state.

Try it​

Unverified

Not yet run on a live cluster for this documentation revision. Uses throwaway objects in the default namespace.

kubectl apply -f - <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata: {name: web}
spec:
replicas: 2
selector: {matchLabels: {app: web}}
template:
metadata: {labels: {app: web}}
spec:
terminationGracePeriodSeconds: 40
containers:
- name: web
image: nginx:1.27-alpine
readinessProbe: # ready only once /tmp/ready exists
exec: {command: ["cat", "/tmp/ready"]}
periodSeconds: 2
lifecycle:
preStop: {exec: {command: ["sleep", "30"]}}
---
apiVersion: v1
kind: Service
metadata: {name: web}
spec:
selector: {app: web}
ports: [{port: 80}]
YAML
kubectl rollout status deploy/web --timeout=10s # times out: nobody is ready

# A helper that prints one line per endpoint
show() { kubectl get endpointslice -l kubernetes.io/service-name=$1 -o jsonpath='{range .items[*].endpoints[*]}{.targetRef.name}{" ready="}{.conditions.ready}{" serving="}{.conditions.serving}{" terminating="}{.conditions.terminating}{"\n"}{end}'; }

# 1. Not-ready Pods are listed, with ready=false
show web

# 2. Make one Pod ready
P=$(kubectl get pod -l app=web -o jsonpath='{.items[0].metadata.name}')
kubectl exec $P -- touch /tmp/ready; sleep 4; show web

# 3. The legacy view hides the difference in a separate list
kubectl get endpoints web -o yaml | grep -A3 -E 'addresses|notReadyAddresses'

# 4. Delete the ready Pod: it drains as serving + terminating
kubectl delete pod $P --wait=false; sleep 2; show web

# 5. A selector-less Service with a hand-written slice
sleep 35 # let the deleted Pod finish draining
IP=$(kubectl get pod -l app=web -o jsonpath='{.items[0].status.podIP}')
kubectl apply -f - <<YAML
apiVersion: v1
kind: Service
metadata: {name: manual}
spec:
ports: [{name: http, port: 80}]
---
apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: manual-1
labels:
kubernetes.io/service-name: manual
endpointslice.kubernetes.io/managed-by: staff
addressType: IPv4
ports: [{name: http, port: 80, protocol: TCP}]
endpoints:
- addresses: ["$IP"]
YAML
kubectl run c --rm -it --restart=Never --image=curlimages/curl:8.5.0 -- curl -sI manual | head -1

kubectl delete svc web manual; kubectl delete endpointslice manual-1; kubectl delete deploy web
  • Step 1 lists two endpoints with ready=false serving=false.
  • Step 2 flips one to ready=true serving=true.
  • Step 3 prints a deprecation warning, then shows the Pods split between addresses and notReadyAddresses.
  • Step 4 shows the deleted Pod as ready=false serving=true terminating=true for about 30 seconds (its preStop sleep), then it disappears.
  • Step 5 returns HTTP/1.1 200 OK even though the manual Service has no selector: kube-proxy does not care who wrote the slice. An unset ready condition counts as ready.

Common misconceptions​

  • "Endpoints and EndpointSlices are two copies I need to check." Slices are what the data path reads. Endpoints exists for older tools and is deprecated.
  • "Only ready Pods appear in the slice." Not-ready and terminating Pods appear too, with conditions saying so.
  • "I can fix a Service by editing its slice." For a Service with a selector, the controller reverts your edit. Fix the selector, labels or readiness instead.
  • "Several slices for one small Service means something is wrong." Slices are not rebalanced on every change; part-full slices are normal.
  • "terminating means the Pod gets no traffic." It gets no new connections while other ready endpoints exist. Established connections continue.

Check yourself​

A Service's slice shows three endpoints, all ready=false serving=false terminating=false. What is wrong, and what do you look at next?

The selector matches, but none of the Pods passes its readiness probe. Look at the Pods' events and probe definition with kubectl describe pod, then at the dependency the probe checks.

Why does the controller not just keep one Endpoints object and send diffs?

Watch events carry whole objects. With one object, every change re-sends every address to every node. Splitting into slices makes the unit of change small.

You hand-edit an EndpointSlice of the booking Service to add an IP. What happens?

booking has a selector, so its slices are managed by the EndpointSlice controller, which rewrites them from the selector and removes your entry.

Where this leads​

Endpoints say where a Service's traffic may go. Callers still need to find the Service's address by name: DNS and namespaces.

References​