how to lookup a SRV record in k8s cluster dns in golang

5/13/2020

I have created headless service and a set of statefulset pods. Using NodeJS, I am able to lookup all IPs of these pods. But I dont know how to do it using GoLang.

dns.resolveSrv(serviceName, function (err, addresses) {
// The app performs a DNS lookup to obtain SRV records.
if (err) {
  response.end("Could not look up DNS SRV records: " + err);
   return;
}...

I did this :

_, addrs, err := net.LookupSRV("dns-tcp", "tcp", "demoapp.default.svc.cluster.local")
if err != nil {
    log.Println(err.Error())
    return "dns wrong"

give me error

lookup _dns-tcp._tcp.demoapp.default.svc.cluster.local on 10.96.0.10:53: no such host
-- cong
dns
go
kubernetes

0 Answers