<p><strong>Information:</strong></p>

<ul>
<li>Kubernetes version: 1.14.1 </li>
<li>Cloud: Azure (not AKS) </li>
<li>DNS: CoreDNS</li>
<li>Deployer: Kubespray </li>
<li>Container: containerd</li>
<li>3 worker nodes</li>
</ul>

<p><strong>Description</strong></p>

<p>I have this statefulset:</p>

<pre><code>---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: busy
spec:
  serviceName: busy
  selector:
    matchLabels:
      app: busy
  replicas: 3
  template:
    metadata:
      name: busy
      labels:
        app: busy
    spec:
      containers:
        - name: busy
          image: busybox:1.28
          imagePullPolicy: IfNotPresent
          command:
            - sleep
            - "3600"
      restartPolicy: Always
</code></pre>

<p>And this headless service:</p>

<pre><code>---
kind: Service
apiVersion: v1
metadata:
  name: busy-headless
spec:
  clusterIP: None
  publishNotReadyAddresses: true
  selector:
    app: busy
</code></pre>

<p>The statefulset creates 3 pods (busy-{1,2,3}). According to the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id" rel="nofollow noreferrer">documentation</a>, each pod should have a DNS record like <code>busy-{1,2,3}.busy-headless.default.svc.cluster.local</code>.</p>

<p><strong>Issue</strong></p>

<p>When I try to resolve the DNS entries associated to the record <code>busy-headless.default.svc.cluster.local</code> from <code>busy-0</code> I get </p>

<pre><code>17:00 $ kubectl exec -ti busy-0 -- nslookup busy-headless.default.svc.cluster.local
Server:    10.233.0.3
Address 1: 10.233.0.3 coredns.kube-system.svc.cluster.local

Name:      busy-headless.default.svc.cluster.local
Address 1: 10.233.67.10 10-233-67-10.busy-headless.default.svc.cluster.local
Address 2: 10.233.68.27 10-233-68-27.busy-headless.default.svc.cluster.local
Address 3: 10.233.68.26 10-233-68-26.busy-headless.default.svc.cluster.local
Address 4: 10.233.69.11 busy-0.busy.default.svc.cluster.local
</code></pre>

<p>From <code>busy-1</code> the command returns <code>busy-1.busy.default.svc.cluster.local</code> for <code>busy-1</code> and <code>10-233-69-11.busy-headless.default.svc.cluster.local</code> for <code>busy-0</code>.</p>

<p>A nslookup on <code>busy-{1,2,3}.busy-headless.default.svc.cluster.local</code> returns an error.</p>

<p>What could possibly be wrong?</p>

<p>Thank you!</p>

Nicolas Labrot
<p>In your StatefulSet manifest try to specify:</p>

<pre><code>serviceName: busy-headless
</code></pre>
