kubernetes-cli command to get dns of a kubernetes resource

2.8k views Asked by At

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 ?

2

There are 2 answers

0
user140547 On BEST ANSWER

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

0
Sameer Naik On

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.