A normal Service hides its Pods behind one IP. Sometimes a client needs to see every Pod.
clusterIP: None
yaml
apiVersion: v1
kind: Service
metadata:
name: web-headless
spec:
clusterIP: None
selector:
app: market-web
ports:
- port: 80None is a literal string, and it is the whole difference. The API server allocates no virtual IP and kube-proxy forwards nothing. The selector still picks the Pods and the Endpoints object still lists them.
market-webDNS gives one IP
kube-proxy picks a Pod
10.42.0.8 · 10.42.0.9 · 10.42.0.10
web-headlessDNS gives every Pod IP
the client picks
10.42.0.8 · 10.42.0.9 · 10.42.0.10
What DNS says
text
learner@shallows:~$ kubectl exec client -- nslookup web-headless
Name: web-headless.straits.svc.cluster.local
Address: 10.42.0.8
Address: 10.42.0.9
Address: 10.42.0.10text
learner@shallows:~$ kubectl get svc web-headless
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web-headless ClusterIP None <none> 80/TCP 4sWhen it matters
A database cluster needs each member to find the others by name: not "a database" but "member 2". A headless Service makes that possible, and Chapter 8's StatefulSets give each Pod its own stable DNS name under one.