Pods in a statefulset and headless service do not get the right dns records

5/24/2019

Information:

  • Kubernetes version: 1.14.1
  • Cloud: Azure (not AKS)
  • DNS: CoreDNS
  • Deployer: Kubespray
  • Container: containerd
  • 3 worker nodes

Description

I have this statefulset:

---
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

And this headless service:

---
kind: Service
apiVersion: v1
metadata:
  name: busy-headless
spec:
  clusterIP: None
  publishNotReadyAddresses: true
  selector:
    app: busy

The statefulset creates 3 pods (busy-{1,2,3}). According to the documentation, each pod should have a DNS record like busy-{1,2,3}.busy-headless.default.svc.cluster.local.

Issue

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

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

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

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

What could possibly be wrong?

Thank you!

-- Nicolas Labrot
kubernetes

1 Answer

5/24/2019

In your StatefulSet manifest try to specify:

serviceName: busy-headless
-- Vasily Angapov
Source: StackOverflow