Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I list all kubernetes DNS records?

Tags:

kubernetes

I have kube-dns running in a (bare metal) cluster. I know that it works, as I can interpolate a service to a name I've created and get a host entry:

$ host elk-service-headless.default.svc.cluster.local
elk-service-headless.default.svc.cluster.local has address 10.42.0.151
elk-service-headless.default.svc.cluster.local has address 10.42.0.152
elk-service-headless.default.svc.cluster.local has address 10.42.0.153
(...)

What I can't figure out how to do is to list all of the records that kube-dns is holding. I've tried the standard DNS tricks like dig and host -l and can't get them. But in any case, there must be a way to do this from Kubernetes itself. I tried inspecting ConfigMaps and didn't find what I'm looking for.

like image 389
tedder42 Avatar asked Jun 22 '19 04:06

tedder42


People also ask

How check DNS services in Kubernetes?

Verify that the DNS service is up by using the kubectl get service command. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ... kube-dns ClusterIP 10.0. 0.10 <none> 53/UDP,53/TCP 1h ...

What is DNS name in Kubernetes?

The Domain Name System (DNS) is a system for associating various types of information – such as IP addresses – with easy-to-remember names. By default most Kubernetes clusters automatically configure an internal DNS service to provide a lightweight mechanism for service discovery.

How do I find the FQDN on a pod?

You can do a DNS query from any pod and you would get the FQDN. cluster-domain. example is just a example in the documentation. cluster.

What is kube-DNS pod?

kube-dns is the authoritative name server for the cluster domain (cluster. local) and it resolves external names recursively. Short names that are not fully qualified, such as myservice , are completed first with local search paths.


2 Answers

This post will help you find the internal DNS record of your K8s services on a cluster that runs kube-dns:

  1. Find the ClusterIP of the kube-dns service:

kubectl -n kube-system get svc kube-dns

enter image description here

Now we know the internal K8s DNS resolver IP is 172.20.0.10

  1. Find the application service endpoint IP:

kubectl -n fe get ep

enter image description here

  1. Exec into the application pod:

kubectl -n fe exec -it fe-app-575fdf6cb6-lt7t6 -- sh

  1. Get DNS service name:

enter image description here

like image 142
AAber Avatar answered Sep 18 '22 13:09

AAber


If you are using kube-dns, it use dnsmaq to cache DNS record, you can dump record by this answer.

If you are using coredns, it embed a cache plugin to cache DNS record, and I find no way to get data in this cache plugin. But I find coredns can use etcd as backend, so the DNS record can be cached in etcd, but this need to reconfig your coredns with this Corefile:

.:53 {
    etcd {
        path /skydns
        endpoint <etcd_endpoint>
        upstream /etc/resolv.conf
    }
    ...
}
like image 29
menya Avatar answered Sep 21 '22 13:09

menya