What Is a Kubernetes Service? Keep Access Stable While Pod Addresses Change
A Kubernetes Service gives clients a stable network name and port for a set of Pods whose addresses and replica count can change. A selector-backed Service tracks matching Pods through EndpointSlices and routes traffic addressed to its virtual IP and DNS name to eligible endpoints. Clients do not need to pin individual Pod IPs.
Why put a Service in front of Pods?
A Deployment creates and removes Pods during updates and recovery. Replacement Pods can have different IP addresses, so a client that stores Pod IPs can break or connect to stale addresses. A Service is the stable logical connection point between clients and the changing backend set.
The default ClusterIP Service receives an internal virtual IP and service port. Cluster DNS lets clients find it by a name such as store-api.shop. The Service controller updates EndpointSlices when matching Pods change. A service proxy or equivalent cluster networking implementation forwards traffic for the Service address and port to an endpoint. The exact forwarding mechanism depends on the cluster implementation.
How labels and ports connect a request
A selector-backed Service finds Pods when spec.selector matches their metadata.labels. EndpointSlices store the Service's network endpoints and ports. Pods that are not ready or are terminating may be excluded from ordinary traffic.
port is the port clients use on the Service; targetPort is the port on the selected Pod. For example, if an application listens on Pod port 8080 while the Service exposes port 80, clients can call http://store-api:80 and the Service forwards to the Pod's named http port. Referencing the named Pod port lets the Service definition remain stable if the numeric container port changes.
Example: connect two web Pods through one internal address
This manifest creates a store-api Service for two Pods labelled app: store-api. A client in namespace shop can use http://store-api:80; a client in another namespace can qualify the name as store-api.shop. Replace the image and readiness path with application-specific values. This is an illustrative manifest; it was not applied to a cluster or verified with a live request.
apiVersion: apps/v1
kind: Deployment
metadata:
name: store-api
namespace: shop
spec:
replicas: 2
selector:
matchLabels:
app: store-api
template:
metadata:
labels:
app: store-api
spec:
containers:
- name: api
image: registry.example.com/team/store-api:<approved-tag-or-digest>
ports:
- name: http
containerPort: 8080
readinessProbe:
httpGet:
path: /ready
port: http
---
apiVersion: v1
kind: Service
metadata:
name: store-api
namespace: shop
spec:
type: ClusterIP
selector:
app: store-api
ports:
- name: http
protocol: TCP
port: 80
targetPort: httpThe Deployment selector, Pod label, and Service selector all use app: store-api. Once the readiness probe succeeds, the Pod can become an eligible Service endpoint. containerPort documents the port and supports name references; it does not force the process to listen there. The application itself must listen on 0.0.0.0:8080 and return success from /ready.
Choose an exposure type
| Type | Address and behavior | Use and limitation |
|---|---|---|
ClusterIP (default) | Cluster-internal virtual IP and DNS name | Internal APIs and services called from within the cluster |
NodePort | A port on each node IP forwards to the Service; the common default allocation range is 30000–32767 | When an external load balancer forwards to nodes; check firewall and node-address scope |
LoadBalancer | Requests an external address from a cloud or installed load-balancer implementation | External clients; without a provider integration, no external balancer may appear |
ExternalName | Returns a DNS CNAME for an external hostname | DNS alias only; no proxying or packet forwarding, and HTTP Host/TLS name differences can cause errors |
LoadBalancer does not mean the Kubernetes API itself supplies a load balancer; a provider or separate controller implements it. NodePort does not configure network exposure or firewall rules safely for you. Host- and path-based external HTTP/HTTPS routing uses Ingress or Gateway API, not a Service type. Ingress needs an Ingress controller.
For StatefulSet-style workloads where clients must discover each replica's address, consider a headless Service. Setting .spec.clusterIP: None omits the virtual IP and lets DNS return individual ready Pod IPs. It does not provide virtual-IP proxying or platform load balancing, so clients must decide how to handle multiple DNS answers.
Apply and verify the connection
These commands are examples and were not run. Check the cluster context and namespace first, and make sure a test request is safe for the application.
kubectl config current-context
kubectl apply -f <store-api.yaml>
kubectl get deployment,pods -n shop -l app=store-api
kubectl get service store-api -n shop -o wide
kubectl get endpointslice -n shop -l kubernetes.io/service-name=store-api
kubectl describe service store-api -n shop
kubectl port-forward service/store-api 8080:80 -n shopAfter a successful apply, the Deployment should reach its requested replica count, the Service should have a ClusterIP, and its EndpointSlice should list ready Pod addresses and ports. Leave port-forward running in one terminal, then check the application from another with curl http://127.0.0.1:8080/ready; stop the forward safely afterward.
If the EndpointSlice is empty, compare the Service selector with Pod labels, verify the namespace, and check whether Pods are Ready. If Pods are ready but requests fail, compare port, targetPort, the actual listening port, and TCP/UDP protocol. If the name does not resolve, check DNS and whether a cross-namespace name such as store-api.shop is needed. A ClusterIP not being reachable from outside the cluster is expected. For external access, inspect LoadBalancer status and provider integration or configure Ingress/Gateway separately.
What a Service does not solve
A Service provides a stable way to reach a Pod group and a traffic-forwarding boundary. It does not automatically add user authentication, TLS termination, HTTP path routing, or fine-grained access control. A readiness probe indicates suitability for Service traffic, not business correctness of responses. Check NetworkPolicy and the cluster networking implementation separately for traffic allow/deny rules.
Sources
[Kubernetes Service concepts and types](https://kubernetes.io/docs/concepts/services-networking/service/)
[EndpointSlices and ready endpoints](https://kubernetes.io/docs/concepts/services-networking/endpoint-slices/)
[DNS for Services and Pods](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/)
[Virtual IPs and Service proxies](https://kubernetes.io/docs/reference/networking/virtual-ips/)
[Ingress HTTP/HTTPS routing and controller requirements](https://kubernetes.io/docs/concepts/services-networking/ingress/)
Scope: selector-based Pod access, discovery and port mapping, Service types, headless Services, and diagnosis. Kubernetes official documentation reviewed on 2026-11-23. The YAML and commands are illustrative and were not executed. Cluster-specific networking, provider load-balancer setup, and NetworkPolicy design are outside scope.