Interview Prep/Kubernetes/Services, DNS, Ingress and NetworkPolicy

A StatefulSet's Pods cannot resolve each other: `nslookup kafka-1.kafka-headless` returns `NXDOMAIN`.

IntermediateTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer

Likely causes → Per-Pod DNS records exist only when the StatefulSet serviceName matches an existing headless Service (clusterIP: None) whose selector matches the Pods. Also, by default only Ready Pods get records, which breaks cluster bootstrap where peers must find each other before ready.

Diagnose →

kubectl get sts kafka -o jsonpath='{.spec.serviceName}{"\n"}'
kubectl get svc kafka-headless -o jsonpath='{.spec.clusterIP} {.spec.selector}{"\n"}'

Fix → Create the headless Service with the same name as serviceName, and for peer discovery during startup set:

spec:
  clusterIP: None
  publishNotReadyAddresses: true

Prevent → Template the StatefulSet and its headless Service together.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, DNS, Ingress and NetworkPolicy