2.1 KiB
Expose your /etc/hosts to Pods on K3s
If we don't have a DNS server and are using /etc/hosts, we will need to do some additional tasks to get the Pods on K3s to resolve names according to /etc/hosts.
This is necessary for AWX to resolve the hostname for your Private Git Repository or pull images from the Container Registry.
One easy way to do this is to use dnsmasq.
-
Add entries to
/etc/hostson your K3s host. Note that the IP addresses have to be replaced with your K3s host's one.sudo tee -a /etc/hosts <<EOF 192.168.0.100 awx.example.com 192.168.0.100 registry.example.com 192.168.0.100 git.example.com 192.168.0.100 galaxy.example.com EOF -
Install and start
dnsmasqwith default configuration.sudo dnf install dnsmasq sudo systemctl enable dnsmasq --now -
Create new
resolv.confto use K3s. Note that the IP addresses have to be replaced with your K3s host's one.sudo echo "nameserver 192.168.0.100" > /etc/rancher/k3s/resolv.conf -
Add
--resolv-conf /etc/rancher/k3s/resolv.confas an argument fork3s servercommand.$ cat /etc/systemd/system/k3s.service ... ExecStart=/usr/local/bin/k3s \ server \ '--write-kubeconfig-mode' \ '644' \ '--resolv-conf' \ 👈👈👈 '/etc/rancher/k3s/resolv.conf' \ 👈👈👈 -
Restart K3s and CoreDNS. The K3s service can be safely restarted without affecting the running resources.
sudo systemctl restart k3s kubectl -n kube-system delete pod -l k8s-app=kube-dns -
Ensure that your hostname can be resolved as defined in
/etc/hosts.$ kubectl run -it --rm --restart=Never busybox --image=busybox:1.28 -- nslookup git.example.com Server: 10.43.0.10 Address 1: 10.43.0.10 kube-dns.kube-system.svc.cluster.local Name: git.example.com Address 1: 192.168.0.100 pod "busybox" deleted -
If you update your
/etc/hosts, restartingdnsmasqis required.sudo systemctl restart dnsmasq