CoreDNS serving /etc/hosts style
The Corefile
CoreDNS configuration is done inside the corefile. I would like to search inside the hosts-file for hostnames matching *.cluster.local. Every other request will be forwarded to 8.8.8.8 and 9.9.9.9.
The DNS-Service will run on udp port 53 (standard DNS). This is important for running via docker to map the correct port(s).
The corefile looks like this:
cluster.local {
hosts /root/cluster.hosts
log
errors
cache
}
.:53 {
forward . 8.8.8.8 9.9.9.9
log
errors
cache
}
Logging and caching actived as well.
The host file for hosts of cluster.local domain looks like this:
# Master
192.168.254.1 master.cluster.local
# Nodes
192.168.254.10 node1.cluster.local
192.168.254.11 node2.cluster.local
Now start the container. Make sure the corefile and host file is in the local volume directory:
Start Docker container:
docker run -d --name coredns --restart=always --volume=/srv/coredns:/root/ -p 53:53/udp coredns/coredns -conf /root/Corefile
Test:
l3the@cluster:/home/l3the $ nslookup node1.cluster.local localhost
Server: localhost
Address: ::1#53
Name: node1.cluster.local
Address: 192.168.254.10
You may have to install nslookup depending on you OS.
For Raspberry OS:
sudo apt-get install dnsutils
Source
https://coredns.io/plugins/hosts/