A Kubernetes Service gives a changing set of pods one stable network identity: a fixed virtual IP and DNS name that load balances traffic across all healthy pods matching a label selector. Because pods are created and destroyed constantly and their IP addresses change, clients talk to the Service instead of to individual pods.
Services are the foundation of service discovery, internal load balancing and external exposure of workloads in a cluster.
A pod gets its own IP address, but that address lives only as long as the pod. A Deployment that scales, rolls out a new version or replaces a crashed pod produces new IPs each time. A Service solves three problems:
orders, not on pod placement.Only pods that pass their readiness probe receive traffic, so rollouts do not send requests to containers that are still starting.
Apply it and inspect the result:
port is the port the Service exposes, and targetPort is the container port that receives the traffic. The selector app: web decides which pods back the Service. Kubernetes tracks the matching pod addresses in EndpointSlice objects, and kube-proxy (or an equivalent dataplane such as Cilium) programs the rules that forward traffic to them.
| Type | Reachable from | Typical use |
|---|---|---|
ClusterIP (default) | Inside the cluster only | Internal microservice communication |
NodePort | Each node IP on a port in the 30000-32767 range by default | Simple external access, development, building block for load balancers |
LoadBalancer | A cloud load balancer with an external IP | Exposing a service on a managed cloud |
ExternalName | Inside the cluster, resolves to a DNS name | Mapping a name to an external service through a CNAME |
Headless (clusterIP: None) | Inside the cluster, DNS returns pod IPs | StatefulSets, client-side load balancing, databases |
A LoadBalancer Service builds on NodePort, which builds on ClusterIP. For HTTP routing by host and path across many services, put an Ingress or a Gateway API route in front of ClusterIP Services rather than creating one cloud load balancer per service.
The cluster DNS (CoreDNS) creates a record for every Service. Within the same namespace a pod reaches it as web; from another namespace as web.default or the full name web.default.svc.cluster.local.
Environment variables with the Service address are also injected into pods started after the Service exists, but DNS is the recommended mechanism.
sessionAffinity: ClientIP to keep a client on the same pod for a period.externalTrafficPolicy: Local on NodePort and LoadBalancer Services, the original client IP is preserved and traffic stays on the receiving node.targetPort so pods can change their container port without editing the Service.If a Service does not respond, check in this order:
kubectl get endpointslices shows addresses. An empty list means the selector matches no ready pods.targetPort equals the port the container really listens on.kubectl get pods), and no NetworkPolicy blocks the traffic.A Service provides stable access and load balancing at the network layer. An Ingress (or Gateway API route) adds HTTP routing rules such as host and path on top of Services.
port is where the Service listens. targetPort is the port on the pod that receives forwarded traffic.
Usually not. The virtual IP exists only as forwarding rules for the configured ports, so test with a TCP or HTTP request.
When clients need individual pod addresses, for example with StatefulSets, or when you do your own load balancing.
A Kubernetes Service provides a stable virtual IP and DNS name, selects pods by labels and balances traffic across ready endpoints. Pick ClusterIP for internal traffic, LoadBalancer or an Ingress for external access, and a headless Service when you need direct pod addresses. Service discovery through CoreDNS lets applications call each other by name no matter how often pods change.