Introduction to Kubernetes Services: ClusterIP, NodePort, LoadBalancer, ExternalName, and headless
How Services find Pods with selectors and EndpointSlices, the five types in practice, svc.cluster.local DNS names tested with nslookup, sessionAffinity, externalTrafficPolicy, and why the path for external HTTP traffic is now the Gateway API.
Kubernetes$ kubectl get endpointslices -l kubernetes.io/service-name=web▍Pods are disposable: on every rollout, reschedule, or node failure, they get a new IP. No client can keep up with that on its own. A Service solves the problem with a stable DNS name and virtual IP that spread traffic across whichever Pods are ready at that moment. In this guide, every Service type was created on a kind cluster with Kubernetes 1.37 (1 control plane and 2 workers, kube-proxy in iptables mode, the default), and the outputs are real, just shortened.
Service types
| Type | What it gives you | When to use it |
|---|---|---|
ClusterIP (default) |
Internal virtual IP + DNS name | Service-to-service traffic inside the cluster |
NodePort |
ClusterIP + a port on every node (default range 30000–32767) | Labs, appliances, when there’s no load balancer |
LoadBalancer |
NodePort + an external load balancer provisioned by a controller | Exposing TCP/UDP outside the cluster in the cloud |
ExternalName |
A CNAME in the cluster DNS, no proxying | Giving an internal name to an external service |
Headless (clusterIP: None) |
DNS that returns the Pod IPs, no virtual IP | StatefulSets, clients that do their own balancing |
The lab: an app that says who answered
To see the load balancing, nginx replies with the Pod name and the caller’s IP:
apiVersion: v1
kind: ConfigMap
metadata:
name: web-conf
namespace: b-svc
data:
default.conf: |
server {
listen 8080;
location / {
default_type text/plain;
return 200 "pod=$hostname client=$remote_addr\n";
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: b-svc
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.29-alpine
ports:
- name: http
containerPort: 8080
readinessProbe:
httpGet: { path: /, port: http }
volumeMounts:
- name: conf
mountPath: /etc/nginx/conf.d
volumes:
- name: conf
configMap:
name: web-conf
ClusterIP
apiVersion: v1
kind: Service
metadata:
name: web
namespace: b-svc
spec:
type: ClusterIP
selector:
app: web
ports:
- name: http
port: 80 # Service port
targetPort: http # container port name (8080)
Using the port name in targetPort decouples the Service from the number used in the image. From a client Pod (kubectl -n b-svc run cli --image=curlimages/curl --command -- sleep 600), six calls spread across the three replicas:
$ kubectl -n b-svc exec cli -- sh -c 'for i in 1 2 3 4 5 6; do curl -s http://web; done'
pod=web-785c7778d7-x87nb client=10.244.1.37
pod=web-785c7778d7-l5vgm client=10.244.1.37
pod=web-785c7778d7-x87nb client=10.244.1.37
pod=web-785c7778d7-x87nb client=10.244.1.37
pod=web-785c7778d7-l5vgm client=10.244.1.37
pod=web-785c7778d7-zxvbl client=10.244.1.37
The distribution isn’t perfect round-robin: in iptables mode the backend is picked at random per connection. Keep in mind, too, that the ClusterIP doesn’t belong to any network interface. It only exists in the rules kube-proxy programs on each node, which is why ping to a ClusterIP usually gets no reply even when the Service works fine. Always test with the real protocol and port, using curl or nc.
Selectors and EndpointSlices
The Service doesn’t store the list of Pods. The EndpointSlice controller watches the Pods that match the selector and writes their addresses into EndpointSlice objects, linked to the Service by the kubernetes.io/service-name label. kube-proxy on each node reads those slices and programs the rules:
$ kubectl -n b-svc get endpointslices -l kubernetes.io/service-name=web
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
web-j2q4x IPv4 8080 10.244.1.32,10.244.2.33,10.244.2.32 4s
$ kubectl -n b-svc get endpointslice -l kubernetes.io/service-name=web -o json \
| jq '.items[0].endpoints[0] | {addresses, ready: .conditions.ready, node: .nodeName, pod: .targetRef.name}'
{
"addresses": [
"10.244.1.32"
],
"ready": true,
"node": "blog-lab-worker2",
"pod": "web-785c7778d7-x87nb"
}
Only endpoints with ready: true get traffic, which is why the readinessProbe matters. When the selector matches nothing, the Service exists and has an IP, but has nowhere to send traffic:
$ kubectl -n b-svc create service clusterip broken --tcp=80:8080 # selector: app=broken
$ kubectl -n b-svc get endpointslices -l kubernetes.io/service-name=broken
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
broken-m2qgb IPv4 <unset> <unset> 0s
$ kubectl -n b-svc exec cli -- curl -s --max-time 3 http://broken; echo "exit=$?"
command terminated with exit code 7
exit=7
“A Service with no endpoints” is the first thing to check when something returns connection refused or times out. More techniques in troubleshooting and debugging.
DNS: svc.cluster.local names
CoreDNS creates a <service>.<namespace>.svc.cluster.local record for every Service. A busybox Pod shows it all:
$ kubectl -n b-svc run dns --restart=Never --image=busybox:1.37 -- sh -c \
'nslookup web.b-svc.svc.cluster.local; cat /etc/resolv.conf; nslookup -type=srv _http._tcp.web.b-svc.svc.cluster.local'
$ kubectl -n b-svc logs dns
Server: 10.96.0.10
Address: 10.96.0.10:53
Name: web.b-svc.svc.cluster.local
Address: 10.96.109.2
search b-svc.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5
_http._tcp.web.b-svc.svc.cluster.local service = 0 100 80 web.b-svc.svc.cluster.local
Thanks to the search list, inside the same namespace web is enough; from another namespace, use web.b-svc. Named ports also produce SRV records, like the _http._tcp one above. ndots:5 makes short names go through several attempts before reaching the right one (an nslookup web in the same Pod showed NXDOMAIN for web.svc.cluster.local and web.cluster.local alongside the correct answer), so for high-volume calls to external domains it’s worth using the FQDN with a trailing dot.
Headless and ExternalName
A headless Service (clusterIP: None) has no virtual IP: DNS returns the IPs of the ready Pods directly. StatefulSets use this to give each replica its own name:
# inside busybox
$ nslookup web-headless.b-svc.svc.cluster.local
Name: web-headless.b-svc.svc.cluster.local
Address: 10.244.2.32
Name: web-headless.b-svc.svc.cluster.local
Address: 10.244.1.32
Name: web-headless.b-svc.svc.cluster.local
Address: 10.244.2.33
ExternalName, on the other hand, is just a CNAME. There’s no proxying and no ports, and the Host header and TLS SNI keep the original name, which can break external HTTPS services:
apiVersion: v1
kind: Service
metadata:
name: external-docs
namespace: b-svc
spec:
type: ExternalName
externalName: kubernetes.io
# inside busybox
$ nslookup external-docs.b-svc.svc.cluster.local
external-docs.b-svc.svc.cluster.local canonical name = kubernetes.io
NodePort
A NodePort opens the same port on every node. We tested it with a container outside the cluster, on the same Docker network as kind:
spec:
type: NodePort
selector:
app: web
ports:
- name: http
port: 80
targetPort: http
nodePort: 30081 # omit it to let the cluster pick
$ docker run --rm --network kind curlimages/curl -s http://172.18.0.6:30081
pod=web-785c7778d7-zxvbl client=10.244.2.1
The Pod saw 10.244.2.1, not the client’s real IP: with the default policy (Cluster), the node applies SNAT before forwarding. We’ll come back to this under externalTrafficPolicy.
LoadBalancer
In the cloud, a LoadBalancer Service makes the cloud controller manager (or a controller like the AWS Load Balancer Controller) create an external load balancer and write its address to status.loadBalancer. kind has no implementation, so the Service stays pending forever and works only as a NodePort:
$ kubectl -n b-svc get svc web-lb
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web-lb LoadBalancer 10.96.96.140 <pending> 80:31161/TCP 52s
To get LoadBalancer IPs on local or bare-metal clusters, the most commonly cited options are cloud-provider-kind (from kubernetes-sigs, built for kind) and MetalLB. Neither was tested in this lab; check each one’s current docs. In the cloud, remember that each LoadBalancer Service usually creates its own load balancer. With dozens of HTTP services, that becomes too much cost and management, and that’s where a shared gateway comes in, the topic of the last section.
sessionAffinity
By default, each connection can land on a different Pod. With sessionAffinity: ClientIP, kube-proxy pins the source IP to one Pod until the timeout:
$ kubectl -n b-svc patch svc web -p \
'{"spec":{"sessionAffinity":"ClientIP","sessionAffinityConfig":{"clientIP":{"timeoutSeconds":600}}}}'
$ kubectl -n b-svc exec cli -- sh -c 'for i in 1 2 3 4 5 6; do curl -s http://web; done'
pod=web-785c7778d7-x87nb client=10.244.1.37
pod=web-785c7778d7-x87nb client=10.244.1.37
... (all six calls on the same Pod)
It’s a patch for applications that keep sessions in memory. Behind NAT, many users share one IP and the load becomes uneven; the real fix is to move state out of the application.
externalTrafficPolicy
This field applies to NodePort and LoadBalancer. With Cluster (the default), any node accepts traffic and forwards it to any Pod, with an extra hop and SNAT. With Local, a node only delivers to its own Pods, preserving the client IP. In the lab, the control plane had no web Pods:
$ kubectl -n b-svc patch svc web-nodeport -p '{"spec":{"externalTrafficPolicy":"Local"}}'
$ for n in blog-lab-control-plane blog-lab-worker blog-lab-worker2; do
ip=$(kubectl get node $n -o jsonpath='{.status.addresses[0].address}'); printf "%s -> " $n
docker run --rm --network kind curlimages/curl -s --max-time 3 http://$ip:30081 || echo timeout
done
blog-lab-control-plane -> timeout
blog-lab-worker -> pod=web-785c7778d7-zxvbl client=172.18.0.9
blog-lab-worker2 -> pod=web-785c7778d7-x87nb client=172.18.0.9
Now the Pod sees the real IP (172.18.0.9), but the node without Pods doesn’t answer. For LoadBalancer Services with Local, Kubernetes allocates a healthCheckNodePort so the load balancer can take those nodes out of the pool:
$ kubectl -n b-svc patch svc web-lb -p '{"spec":{"externalTrafficPolicy":"Local"}}'
$ kubectl -n b-svc get svc web-lb -o jsonpath='{.spec.healthCheckNodePort}'
31504
# control plane (172.18.0.7), no local Pods
$ docker run --rm --network kind curlimages/curl -s -w ' HTTP %{http_code}' http://172.18.0.7:31504/
{
"service": {
"namespace": "b-svc",
"name": "web-lb"
},
"localEndpoints": 0,
"serviceProxyHealthy": true
} HTTP 503
The side effect is uneven distribution when Pods aren’t spread across nodes. For internal traffic, the equivalent field is internalTrafficPolicy.
What about Ingress? Use the Gateway API
Services work at L4. For HTTP routing by host and path, TLS, and a single entry point, the classic resource is Ingress, and the most popular controller was Ingress NGINX. The Kubernetes project has retired it: the announcement came in November 2025, maintenance ended in March 2026, and the repository is archived, with no further fixes or CVE patches. Existing installs keep running, but the recommended path is the Gateway API (v1.7.0 at the time of writing; check the current version), with the ingress2gateway tool to convert manifests, or another maintained controller. The details are in Kubernetes networking and, for an API gateway, in how to configure Kong.
Checklist
- Use named ports in
targetPort - Check EndpointSlices when a Service doesn’t respond
- Configure a readinessProbe on every Service backend
- Call services as
<svc>.<ns>across namespaces and by FQDN with a trailing dot for external domains - Consider
externalTrafficPolicy: Localwhen the client IP matters - Avoid
sessionAffinityas a permanent fix for in-memory state - Plan the migration from Ingress NGINX to the Gateway API
A Service is a simple promise: a name that doesn’t change in front of Pods that change all the time. Understanding how that promise is kept shortens any network investigation.