How to get FQDN DNS name of a kubernetes service?
Asked Answered
J

2

11

How to get a full FQDN of the service inside Kubernetes?

➜ k get svc -o wide  
NAME                     TYPE           CLUSTER-IP       EXTERNAL-IP                             PORT(S)    AGE     SELECTOR
airflow-flower-service   ClusterIP      172.20.119.107   <none>                                  5555/TCP   20d     app=edna-airflow
airflow-service          ClusterIP      172.20.76.63     <none>                                  80/TCP     20d     app=edna-airflow
backend-service          ClusterIP      172.20.39.154    <none>                                  80/TCP     20d     app=edna-backend

so how to query internal Kubernetes DNS to get the FQDN of the backend-service for example?

Jen answered 3/9, 2020 at 22:20 Comment(0)
R
23

Go inside any pod in the same namespace with kubectl exec -ti <your pod> bash and then run nslookup <your service> which will typically be, unless you change some configurations in the cluster to: yourservice.yournamespace.svc.cluster.local

Redouble answered 3/9, 2020 at 23:1 Comment(2)
To install nslookup utility in your pod apt update and apt-get install dnsutilsConover
apt-get is only available inside Debian derived containers. If you're not on Debian or related you need to use the package manager of your distribution and the package may be called differently.Demodulator
C
0

You can get it for all services (if it is known)

kubectl get services -o jsonpath='{range .items[*]}{.metadata.annotations.kubernetes\.fqdn}' ; echo

or a particular service

kubectl get service $SERVICE_NAME -o jsonpath='{range .items[*]}{.metadata.annotations.kubernetes\.fqdn}' ; echo
Conversant answered 13/9 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.