1

I have gone through the doc mentioned here gitlink as well as doclink

But my job would be a whole lot easier if I could get the dns of a resource type by using any kubernetes command. Also tried this commands-link

For example, i would like to get the dns name of a service db-service running in dev namespace inside svc.cluster.local

db-service.dev.svc.cluster.local

Any pointers ?

codeaprendiz
  • 2,703
  • 1
  • 25
  • 49
  • Except in a couple of specific cases (like pods attached to stateful sets), things that aren't services don't have DNS names, and the service name is very easy to mechanically construct. Do you have a use case for something that's not a service that still needs this lookup? – David Maze Dec 22 '20 at 20:58
  • Ah okay thanks a lot @DavidMaze, I was just trying to learn more about this. I was hoping to basically get as much info from commands as possible so that I do not have to construct things mechanically :). – codeaprendiz Dec 22 '20 at 21:06

2 Answers2

6

If you need to, you can query that in a pod:

How do I run a container from the command line in Kubernetes (like docker run)?

Retrieve the full name of a service in Kubernetes

using a pod which has some DNS utils

kubectl run tmp-shell --rm -i --tty --image tutum/dnsutils -- /bin/bash

you can then run

root@tmp-shell:/# nslookup db-service
Server:     10.2.32.10
Address:    10.2.32.10#53

Name:   db-service.dev.svc.cluster.local

for a one-liner, see: https://serverfault.com/questions/929211/kubernetes-pod-dns-resolution

user140547
  • 7,750
  • 3
  • 28
  • 80
1

Try command

kubectl get svc

First column is internal DNS name. If the type is LoadBalancer then EXTERNAL-IP column will display the external DNS name.

Sameer Naik
  • 1,326
  • 1
  • 13
  • 28