Headless Services

Headless Services and StatefulSet Networking

With clusterIP: None a Service is headless: no virtual IP, and its name resolves to the ready Pods' own addresses, for clients that choose a peer themselves, such as databases and gRPC:

A normal Service name returns one IP; a headless one returns every PodShell
kubectl apply -f - >/dev/null <<'EOF'
apiVersion: v1
kind: Service
metadata: { name: api-headless }
spec: { clusterIP: None, selector: { app: booknest, tier: api }, ports: [{ port: 3000 }] }
EOF
for s in api api-headless; do echo "$s:"
  kubectl exec client -- nslookup $s 2>/dev/null | grep '^Address: '; done
Output
api:
Address: 10.96.121.82
api-headless:
Address: 10.244.1.105
Address: 10.244.1.104
Address: 10.244.1.106

A headless Service named in a StatefulSet's serviceName (StatefulSets and PostgreSQL) gives each replica a stable name, such as postgres-0.postgres.booknest.svc.cluster.local, that survives rescheduling while its IP changes.