Core DNS

sonu kushwaha
6 min readAug 8, 2021

--

Lets, first talk about the DNS(Domain Name System Service) with an example, suppose we have two nodes ie node A and node B. And one want to establish connection b/w both the nodes , we need to ping it with the help of ip address of that particular node .

sometimes it becomes very overwhelming to remember ip address of different services or pods for connection , so what DNS does is , create/have centralized database where it will maintain the ip of nodes along with its hostname.

now, if some node ping’s via its hostname as on DNS database ,it establish the connection b/w both the nodes. The node we are pinging must also know its DNS server address(address of DNS data base) like on windows if we give following command we will get the location of DNS server

ipconfig /all

C:\Users\Sonu>ipconfig /allWireless LAN adapter Wi-Fi:Connection-specific DNS Suffix  . :
Description . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX201 160MHz
Physical Address. . . . . . . . . : 6E-FF-98-4E-66-BA
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::e0e3:42aa:6d3a:5917%17(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.254.7(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Saturday, August 7, 2021 8:05:48 AM
Lease Expires . . . . . . . . . . : Sunday, August 8, 2021 8:05:48 AM
Default Gateway . . . . . . . . . : 192.168.254.254
DHCP Server . . . . . . . . . . . : 192.168.254.254
DHCPv6 IAID . . . . . . . . . . . : 292487064
DHCPv6 Client DUID. . . . . . . . : 00-03-00-01-6E-FF-98-4E-66-BA
DNS Servers . . . . . . . . . . . : 202.94.66.2
202.94.66.3

NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter Bluetooth Network Connection:Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
Physical Address. . . . . . . . . : 54-8D-5A-9C-22-3B
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

To create own DNS server:-

we have the following products available namely

  • BIND
  • DNS MASQ
  • CORE DNS

Core DNS

It is third party component ,which can be used in different field but its some how very much helpful for the kubernetes product.

its is very much light weight tool as it work on concept of plugins, so we might require different plugins for extra support.

lets first have a look on internal working of CoreDNS ie irrespective of kubernetes usage and its installation

1)wget CoreDNS(to download the CoreDNS package )

2)untar the CoreDNS package downloaded above

tar -xvzf coredns_1.8.4_linux_amd64.tgz

now we are done with the installation part ,so we need to create database where we will maintain the ip and the host name. here i have created a file called “sonudb” as you can refer the following image for the same.(remember CoreDNS runs on port 53 ie udp protocol)As you can see there is no service running on the port 53 be it TCP or UDP

content of file sonudb
no service port running on 53

what we need to do now is provide the location of the database file sonudb to the server so that if client hits DNS server it can refer to the database file for hostname . hence before starting the CoreDNS service we need to provide the conf file which will hold the path of database file .

i have created a file with sonucoredns.conf that holds the location of database and the have started CoreDNS service .refer following image

we are done on server side configuration ,now setting up on client side

what we are going to do is on the client side we are going to change the nameserver ip to our CoreDNS server ip and the nameserver details is present in the file called /etc/resolve.conf(this location is specific to Linux)

CoreDNS server ip address is 192.168.254.29

you can see in the following pic i am able to ping sonu.in and nslookup command is also giving the server ip with port ie 53 refer following image

ping and nslookup was successful

and if we provide the wrong hostname it will give following output

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

USECASE OF CoreDNS with KUBERNETES

Suppose that we have exposed certain deployment with the service ie node port in our case and all the pods under that deployment get exposed to a single IP address of the service(loadbalancer) so what one can do is provide the service ip to the database of the DNS server with host name that can be easly remembered .

But remember there might be case that the service we created might face single point of failure (SPoF). so in that case we need to again create nwe service /load balancer which will have totally new IP address hence we need to manually update the database of the DNS server with the new new IP of service exposed therefore in this case Service discovery comes into action that will auto detect the SPoF of service and will also update the ip of service to the db of the DNS server.

--

--