A StatefulSet or Pod is trying to connect to a headless Service that does not exist or is not properly configured. This breaks DNS-based service discovery.
Headless Services (with clusterIP: None) provide DNS entries for individual Pod IPs instead of a single Service IP. This is critical for StatefulSets and applications needing direct Pod-to-Pod communication. When a headless service is missing or misconfigured, DNS resolution fails and Pods cannot discover each other.
Check if the service is created:
kubectl get svc -n your-namespaceLook for the service name (typically matches the StatefulSet name). If missing, create it.
Create a headless service YAML:
apiVersion: v1
kind: Service
metadata:
name: my-db
namespace: default
spec:
clusterIP: None # This makes it headless
selector:
app: my-db
ports:
- port: 5432
targetPort: 5432Apply it:
kubectl apply -f service.yamlEnsure your StatefulSet Pods have the matching labels:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: my-db
spec:
serviceName: my-db # Must match service name
selector:
matchLabels:
app: my-db # Must match service selector
template:
metadata:
labels:
app: my-dbFrom within a Pod, test if the service resolves:
kubectl exec -it my-db-0 -- nslookup my-db.default.svc.cluster.localYou should get multiple A records (one per Pod). For a service with 3 replicas, you should see 3 IPs.
Verify that running Pods have the correct labels:
kubectl get pods --show-labelsConfirm all Pods have the label referenced in the service selector. If not, recreate the StatefulSet.
StatefulSets require the serviceName field to be set to the headless service. The service must exist before the StatefulSet is created. For multi-zone clusters, ensure DNS is properly configured across zones. Some service meshes (Istio, Linkerd) may interfere with headless service discovery—check mesh documentation if using one.
Failed to connect to server: connection refused (HTTP/2)
How to fix "HTTP/2 connection refused" error in Kubernetes
missing request for cpu in container
How to fix "missing request for cpu in container" in Kubernetes HPA
error: invalid configuration
How to fix "error: invalid configuration" in Kubernetes
etcdserver: cluster ID mismatch
How to fix "etcdserver: cluster ID mismatch" in Kubernetes
running with swap on is not supported
How to fix "running with swap on is not supported" in kubeadm