Appearance

Services and EndpointSlices

Give a changing set of Pods a stable Service address and inspect the backends Kubernetes can route to.

What you will understand

  • Follow a Service selector from matching labels to EndpointSlice entries.
  • Trace a connection from a ClusterIP and Service port to the application port.
  • Verify Service connectivity from a client Pod inside the cluster.

Builds on: Probes and graceful recovery

How a Service finds replaceable backends

A catalog frontend needs to call a catalog API. The API runs in a Pod today, and its replacement could have a different IP tomorrow. A Service gives clients a stable name and a way to reach the current backends. A Service of type ClusterIP gets a virtual IP for use inside the cluster. A client connects to that IP and the Service port. The network implementation forwards the connection to an eligible backend.

For a Service with a selector, Kubernetes looks for Pods in the same namespace whose labels match. The EndpointSlice controller records matching backend addresses, ports, and conditions in objects called EndpointSlices. You can think of the Service as the address clients use and the slices as the list the network implementation uses to learn where traffic can go. Toggle a backend’s readiness in the first scene and compare the selected Pods with the eligible endpoints.

Which Pods can be Service backends?

The Service selector finds label matches. EndpointSlices publish their addresses and readiness, and ordinary forwarding uses eligible endpoints.

  1. Match app=service-demo

    The Service selector app=service-demo matches A and B. A healthy Pod with another label is outside this backend set.

  2. Record readiness per address

    The EndpointSlice controller maintains addresses, target ports, and readiness conditions. An unready address can remain represented with ready false.

  3. Update addresses as Pods change

    When a replacement Pod gets a new IP and becomes ready, the endpoint records change. The Service frontend remains stable.

A normal selector-based Service is shown with publishNotReadyAddresses omitted.

Try the mechanism with your own inputs
2 eligible endpointsThe selector app=web and readiness together produce web-a, web-b. A container can remain running while unready. This models a Service with publishNotReadyAddresses=false and no terminating endpoints; readiness alone does not describe every Service routing policy.. Service, selector app=web, active. web-a, app=web, ready. web-b, app=web, ready. api-a, app=api, idleService: selector app=web
Serviceselector app=webIn focus
web-a: app=web
web-aapp=webReady
web-b: app=web
web-bapp=webReady
api-a: app=api
api-aapp=apiContext
Serviceselector app=webIn focus
web-aapp=webReady
web-bapp=webReady
api-aapp=apiContext
2 eligible endpoints

The selector app=web and readiness together produce web-a, web-b. A container can remain running while unready. This models a Service with publishNotReadyAddresses=false and no terminating endpoints; readiness alone does not describe every Service routing policy.

spec:
  selector:
    app: web
# publishNotReadyAddresses defaults to false.
# Selected non-terminating ready endpoints: web-a, web-b
Explore another case

Connect a Service port to the app’s listener

Save the example as service-demo.yaml and apply it in a disposable namespace. The Deployment starts nginx on port 80 and gives the Pod the label app: service-demo. The Service selects that label and accepts TCP connections on port 8080. Its targetPort: http refers to the port named http in each selected Pod. That name resolves to 80 in this example. Setting containerPort documents and names a port. The process in the container still has to listen there.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: service-demo
  template:
    metadata:
      labels:
        app: service-demo
    spec:
      containers:
        - name: web
          image: nginx:1.27.5
          ports:
            - name: http
              containerPort: 80
          readinessProbe:
            httpGet:
              path: /
              port: http
---
apiVersion: v1
kind: Service
metadata:
  name: service-demo
spec:
  type: ClusterIP
  selector:
    app: service-demo
  ports:
    - name: http
      protocol: TCP
      port: 8080 # Client-facing Service port.
      targetPort: http # Resolves to the Pod's named port 80.
kubectl apply -f service-demo.yaml
kubectl get service service-demo
kubectl get pods -l app=service-demo --show-labels
kubectl get endpointslices -l kubernetes.io/service-name=service-demo -o yaml

Check the Service address and compare the Pod IP with the addresses in its slices. Look for conditions.ready beside the backend. Send a request in the forwarding scene. Follow it from the client to the ready Pod and watch the response return. On a cluster using kube-proxy, it updates rules used to handle Service traffic. Some network implementations handle that job differently.

Open Inspect the request to follow one iptables example. Compare the destination before and after forwarding, then check what source address the client sees on the reply.

Where does a request to a Service go?

Send an HTTP request to port 8080 and follow the connection to nginx on port 80. The EndpointSlice below shows the available addresses.

Client Podservice-clientRequests GET /
Service address10.96.0.42:8080Node forwarding rules
Backend Pod10.244.1.7:80nginx · Ready
EndpointSliceUsed to program the node’s forwarding rules
  • 10.244.1.7:80Ready · eligible
  • 10.244.2.9:80Not ready · skipped
The Service has a ready backend

The client already knows the Service’s virtual IP. The node has forwarding rules for its ready endpoint.

Text walkthrough
  1. The Service has a ready backend

    The client already knows the Service’s virtual IP. The node has forwarding rules for its ready endpoint.

  2. Client connects to the Service address

    The client targets 10.96.0.42:8080. The node’s forwarding rules select an eligible backend.

  3. The connection is forwarded to port 80

    The node directs the connection to 10.244.1.7:80. The client sends GET / over that connection.

  4. nginx receives GET /

    The ready Pod handles the request on its own IP and port.

  5. The response is on its way back

    nginx sends HTTP 200. The reply follows the established connection back to the client.

  6. The client receives HTTP 200

    One request reached a ready backend through the Service’s stable address.

IPv4 ClusterIP with one ready and one unready endpoint. DNS resolution, TCP handshakes and the details of address translation are omitted. The EndpointSlice supplies endpoint data to the networking implementation.

Inspect the request

A ClusterIP connection in a cluster using kube-proxy in iptables mode. Start with how the node gets its forwarding rules, then follow one HTTP request.

1 / 6

From EndpointSlice controllerTo API server

Publish eligible endpoints

The controller records the addresses and readiness of the Service’s matching Pods. An unready Pod can still appear in an EndpointSlice.

EndpointSlice ready addresses
Before
No address published yet
After
10.244.1.7:80 is ready
Publish eligible endpoints

The controller records the addresses and readiness of the Service’s matching Pods. An unready Pod can still appear in an EndpointSlice.

Illustrative addresses and playback timing. The client already knows the Service IP. TCP handshake and other packet fields are omitted.

If the Service selector stops matching, which will fail first, the DNS lookup or the HTTP request?
Reveal prediction answer

DNS can still return the Service IP. With no matching Pods, forwarding has no eligible backend, so the HTTP request fails.

Compare the Service selector, EndpointSlice readiness, and HTTP from the original client before and after the repair.

Verify this in the Service lab
Explore another case

Test from a Pod inside the cluster

Run the sample client in the same namespace. The short name service-demo resolves there, and the request goes to port 8080. The client exits after fetching the page, so the wait looks for Succeeded. Read its logs to see the nginx response, then remove the client Pod.

kubectl run service-client --image=busybox:1.36.1 --restart=Never \
  --command -- sh -c 'wget -qO- http://service-demo:8080/'
# This finite client can finish before a Ready condition is observed.
kubectl wait --for=jsonpath='{.status.phase}'=Succeeded pod/service-client --timeout=90s
kubectl logs service-client
kubectl delete pod service-client

Repeat after checking the selector and endpoint addresses in the Service networking lab. If you change a label to break the match, observe which fields change before restoring it.

Read endpoint conditions

An EndpointSlice entry can still show a Pod address while ready is false. Inspect conditions as well as the address. Options such as publishing unready addresses and routing behavior during termination affect special cases. When debugging a typical Service, first confirm matching Pods, ready backends, and agreement between the target port and the application listener.

Check your understanding

The Service exists and DNS returns an IP, but its selector says app: catalog while the Pods say app: catalogue. Where will the connection go?

The labels do not match, so this Service has no eligible backends from those Pods. Its name can still resolve to the ClusterIP. Compare the selector with the Pod labels and correct the intended match before debugging the application itself.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu