Search code examples
google-kubernetes-enginekube-dnsgke-networking

Why do kube-dns SRV entries have 0 for the port number of a service in a GKE cluster?


I have a free trial cluster in GKE. In this cluster I have a deployment and a service. When I do nslookup -type=srv <service_name> inside a helper pod with DNS utils, I get entries containing 0 instead of the actual port (eg 17000) number of the service. This problem prevents me from moving on. I will be glad for your help.

C:\>kubectl exec dnsutils -- nslookup -type=srv my-svc
;; Truncated, retrying in TCP mode.
Server:         10.120.0.10
Address:        10.120.0.10#53

my-svc.my-ns.svc.cluster.local   service = 10 14 0 3133626239396130.my-svc.my-ns.svc.cluster.local.
my-svc.my-ns.svc.cluster.local   service = 10 14 0 6333336363666162.my-svc.my-ns.svc.cluster.local.
my-svc.my-ns.svc.cluster.local   service = 10 14 0 3132373039303465.my-svc.my-ns.svc.cluster.local.
my-svc.my-ns.svc.cluster.local   service = 10 14 0 3838326161363637.my-svc.my-ns.svc.cluster.local.
my-svc.my-ns.svc.cluster.local   service = 10 14 0 3135393163303035.my-svc.my-ns.svc.cluster.local.
my-svc.my-ns.svc.cluster.local   service = 10 14 0 3463343863303565.my-svc.my-ns.svc.cluster.local.
my-svc.my-ns.svc.cluster.local   service = 10 14 0 3436353934633363.my-svc.my-ns.svc.cluster.local.

Solution

  • "The first command that was ran will only indicate that an SRV record exists but will not actually tell us the port. To get the port, we need to explicitly look it up using the _portname._protocol format. I.e. if "my-svc" has a port named "grpc" in the "my-ns" namespace, you would run kubectl exec dnsutils -- nslookup -type=srv _grpc._tcp.my-svc.my-ns.svc.cluster.local to get the port for the grpc service. See DNS SRV port lookup fails as well for an explanation as to why this is the case.

    In the Service definition, the port can be named and we can replace my-port-name with that name using the _my-port-name._tcp.my-svc.my-ns.svc.cluster.local syntax" - @Gari Singh.