The next step is to set up Dnsmasq on two of the MicroK8s nodes. We are going to use Dnsmasq as a lightweight caching DNS service that also resolves all of our local MicroK8s hosts to the domain name kubeflow.ubuntu.local
, in order to set up round-robin DNS.
Round-robin DNS
Round-robin DNS is a way to ensure improved service availability and load-balancing via DNS, by load-balancing requests across multiple DNS records with the same ‘A’ record but different IP addresses.
First let’s install the Dnsmasq package. Again, on each node in the MicroK8s cluster, run the following command:
sudo apt install dnsmasq -y
Next we need to configure the Dnsmasq daemon. We want Dnsmasq to listen for DNS lookup requests on our MicroK8s nodes’ loopback interface as well as on the public interface. Note that your server may have more than one network interface - make sure you choose the right one!
You can find a lot of information about your MicroK8s node’s network configuration by running the following command:
ip addr
Ok, let’s go ahead and configure Dnsmasq. Note that you should replace the IP address assigned to the variable PUBLIC_IP
with your own MicroK8s cluster node’s public IP address, which will likely be different to the one shown below.
Run these commands on each MicroK8s cluster node to set up Dnsmasq as a caching DNS server that recursively forwards unknown lookups to Google’s public DNS:
PUBLIC_IP=192.168.100.10
cat << EOF > dnsmasq.local.conf
domain-needed
bogus-priv
no-poll
server=8.8.8.8
server=8.8.4.4
listen-address=$PUBLIC_IP
except-interface=l0
bind-interfaces
EOF
cat dnsmasq.local.conf | sudo tee -a /etc/dnsmasq.d/local.conf
The next step is to set up static records for Dnsmasq on each of the nodes where Dnsmasq is running. We want to create a static record for each node in the MicroK8s cluster. On each node in the MicroK8s cluster, run the following commands:
declare -a microk8s_cluster=("192.168.100.10" "192.168.100.11" "192.168.100.12")
for node in ${microk8s_cluster[@]}; do
echo "$node kubeflow.ubuntu.local" | sudo tee -a /etc/hosts
done
Alright, we want to bounce Dnsmasq so that it picks up our configuration changes.
sudo systemctl enable dnsmasq
sudo systemctl restart dnsmasq
But there are some extra steps here, to ensure that our servers and clients using systemd-resolved can make use of Dnsmasq. On each node of the cluster, and the systems that will access it, run the following commands:
echo "DNS=192.168.100.10" | sudo tee -a /etc/systemd/resolved.conf
echo "FallbackDNS=192.168.100.11" | sudo tee -a /etc/systemd/resolved.conf
sudo systemctl restart systemd-resolved
sudo systemd-resolve --flush-caches