Appearance

Services and EndpointSlices

Separate stable service identity, changing backend records, and node data-plane forwarding.

What you will understand

  • Map Service selectors to EndpointSlice backend records
  • Distinguish port, targetPort, and ClusterIP
  • Explain why a Service is not a central proxy process

Builds on: Probes and graceful recovery

Mental model: stable address, replaceable backends

A Service gives clients a stable network abstraction over a changing set of endpoints. Pods come and go, names and IPs change, and a client should not need a manually updated list after each rollout. A normal selector-based Service declares which Pod labels belong to its backend set and which ports clients use. Its default type, ClusterIP, allocates a cluster-internal virtual IP for the Service’s lifetime.

A Service is an API object, not necessarily a process that every request passes through. The control plane tracks relevant backends in EndpointSlices. A node data-plane implementation watches Services and EndpointSlices and programs packet forwarding or equivalent behavior. kube-proxy is one common implementation; other networking implementations can provide replacement behavior, including eBPF-based paths. The Service IP is a virtual frontend abstraction, not proof that a central “Service server” owns a socket at that IP.

An EndpointSlice records endpoint addresses, ports, and conditions such as ready, serving, and terminating. For normal selector-based Services, a controller maintains these records as matching Pods change. A Service can span multiple EndpointSlices; inspect them all using the kubernetes.io/service-name label rather than assuming one object contains every backend. The records describe the target set and health information; they do not themselves forward packets.

Service selection becomes EndpointSlice state

Follow Pod labels and readiness into controller-maintained backend records.

Ownership viewStep 1 of 3
Select matching Pods in the namespaceThe Service selector app=service-demo matches A and B. A healthy Pod with another label is outside this backend set.. Service app=service-demo, active. Pod A: matching, ready, ready. Pod B: matching, unready, warning. Pod C: other label, readyService app=service-demo
Service app=service-demoIn focus
Pod A: matching, ready
Pod A: matching, readyReady
Pod B: matching, unready
Pod B: matching, unreadyWarning
Pod C: other label
Pod C: other labelReady
Service app=service-demoIn focus
Pod A: matching, readyReady
Pod B: matching, unreadyWarning
Pod C: other labelReady
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: selector matches nothing
Select matching Pods in the namespace

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

Read the complete visual sequence
  1. Select matching Pods in the namespace

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

  2. Record endpoint addresses and conditions

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

  3. Update records as Pods are replaced

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

Failure: selector matches nothing

Failure: selector matches nothing

  1. The Service selector is wrong

    The Service says app=typo while all intended Pods use app=service-demo.

  2. The frontend exists without usable backends

    ClusterIP allocation succeeds independently of the selector. EndpointSlices provide no matching ready addresses for this request path.

  3. Inspect actual Pod labels and repair the selector

    Correct only the intended selection, then wait for endpoint records to reconcile and test from the caller.

About this model

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

Walkthrough: expose an existing listener

The following complete example declares one web replica and a Service. Save it as service-demo.yaml and apply it in a dedicated namespace. nginx listens on 80. Clients use Service port 8080, which targets the Pod’s named http port resolving to 80.

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

Expect an allocated ClusterIP and, once the Pod is ready, an endpoint address corresponding to the Pod IP with target port 80. Do not hard-code the sample cluster’s allocated address into reusable manifests. The stable DNS name introduced next is normally a better application configuration reference.

A virtual frontend programs a data path

Separate API objects from node forwarding and actual backend listeners.

Flow viewStep 1 of 3
Configure frontend and target portsService port 8080 is for clients. targetPort http resolves to Pod port 80, where nginx actually listens.. ClusterIP:8080, ready. Backend Pod IP:80, ready. nginx listener :80, readyClusterIP:8080
ClusterIP:8080Ready
Backend Pod IP:80
Backend Pod IP:80Ready
nginx listener :80
nginx listener :80Ready
ClusterIP:8080Ready
Backend Pod IP:80Ready
nginx listener :80Ready
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: targetPort points to no listener
Configure frontend and target ports

Service port 8080 is for clients. targetPort http resolves to Pod port 80, where nginx actually listens.

Read the complete visual sequence
  1. Configure frontend and target ports

    Service port 8080 is for clients. targetPort http resolves to Pod port 80, where nginx actually listens.

  2. Program node forwarding

    The Service implementation observes Service and EndpointSlice data, then programs node forwarding. The API object is not a central request-handling process.

  3. Forward the client connection

    The client connects to the virtual frontend. The data plane selects a backend and delivers traffic to its real listener.

Failure: targetPort points to no listener

Failure: targetPort points to no listener

  1. Selection is correct

    The Service matches healthy Pods but maps its port to numeric targetPort 8081. nginx still listens on 80.

  2. Packets reach the wrong endpoint

    The address can be correct while the destination port has no server. Endpoint presence alone does not validate the listener.

  3. Align the mapping and retest

    Set targetPort to the real listener or its valid named port. Retest the Service path from the same client network.

About this model

One common node Service implementation is represented abstractly; no particular proxy mode is assumed.

Practice: test from the caller’s network

Use a disposable client Pod in the same namespace. BusyBox provides a small HTTP client for this training test. If your cluster restricts debug images or egress, use an approved equivalent.

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

A successful HTTP body shows name resolution and the tested in-cluster Service request path worked for that caller. If the completion wait times out, inspect the client’s status and logs before deleting it; a Failed client is different from one still preparing its image. Success does not prove external exposure or every backend’s behavior. Service forwarding commonly selects a backend per connection or flow, not round-robin for each HTTP request. Connection reuse can make several requests reach the same Pod; do not infer a balancing bug from a small sequence without understanding client connections.

Change only the Service selector to an unmatched label in the lab. The Service and ClusterIP can remain present while the backend set becomes empty. Restore the selector and inspect the EndpointSlice records again. Alternatively, a wrong numeric targetPort can leave selected endpoint addresses visible but send connections to an unused Pod port. Selection and listener mapping are different boundaries.

Pitfalls

Readiness does not delete a Pod or necessarily remove its address from every EndpointSlice. Conditions can mark it ineligible for ordinary traffic while retaining the record. publishNotReadyAddresses and terminating-endpoint handling alter ordinary behavior, so read the actual Service configuration. Endpoint propagation is asynchronous; do not promise that readiness loss instantly ends existing connections.

Check your understanding

A Service has a ClusterIP but no ready backend. Does the allocated IP prove that a healthy proxy process exists?

No. The Service object and virtual IP can exist independently of healthy backend Pods. Inspect selector matches, endpoint addresses and conditions, target ports, and the node forwarding implementation. Creating or recreating the Service alone will not repair an application that cannot become ready.

Practice selector and target-port failures in the module lab. Next, distinguish internal discovery from reaching the cluster externally.

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.