Resolving pod in GKE DNS

282 views Asked by At

I have a question regarding kube-dns in GKE. When I deploy a statefulset, it will stores all records base on the pod name. e.g

dig  _mysql._tcp.powerdns-recursor-database-cluster.default.svc.cluster.local. SRV

;; ANSWER SECTION:
_mysql._tcp.powerdns-recursor-database-cluster.default.svc.cluster.local. 30 IN SRV 10 50 3306 powerdns-recursor-database-cluster-1.powerdns-recursor-database-cluster.default.svc.cluster.local.
_mysql._tcp.powerdns-recursor-database-cluster.default.svc.cluster.local. 30 IN SRV 10 50 3306 powerdns-recursor-database-cluster-0.powerdns-recursor-database-cluster.default.svc.cluster.local.

So as you can see, it will return

powerdns-recursor-database-cluster-1

and

powerdns-recursor-database-cluster-0

which is a correct pod name.

But I have a CRD and in backend, my controller will deploy a statefulset but the records are very different.

dig _foo._udp.test.default.svc.cluster.local. SRV


;; ANSWER SECTION:
_foo._udp.test.default.svc.cluster.local. 30 IN SRV 10 50 4060 3838313432393332.test.default.svc.cluster.local.
_foo._udp.test.default.svc.cluster.local. 30 IN SRV 10 50 4060 3531343631663839.test.default.svc.cluster.local.

As you can see here, it returns

3838313432393332

and

3531343631663839

as pod name. Usually kubernetes returns pod name or pod ip in the "-" format but I don't know what is these numbers and how kube-dns storing them and why using CRD is different than statefulset? Is there anyway to use pod name also here?

1

There are 1 answers

0
Behnam Hooshiarkashani On

After a lot of tries, I found the issue.

In general, we have two ways for connecting a headless service to a StatefulSet.

  1. Using "serviceName" in StatefulSet serviceName: "test"
  2. Using selector in Service selector:
  3. Using both way (serviceName + selector)

In case of using empty "serviceName" it will not use podName in GKE internal DNS (kubeDNS or CloudDNS). So if we need to have PodName in our DNS records, we have to write serviceName in our statefulSet.