To address missing DNS entries in some VMs, follow the steps below to manually add nameservers and search domain to k3s:
Create a file
/etc/rancher/k3s/resolv.conf
with the following data.
Data:vi /etc/rancher/k3s/resolv.conf
nameserver <DNS_IP_1> nameserver <DNS_IP_2> search <DOMAIN_1> <DOMAIN_2>
Create another file
/etc/rancher/k3s/config.yaml
with the following data.
Data:vi /etc/rancher/k3s/config.yaml
kubelet-arg: - "resolv-conf=/etc/rancher/k3s/resolv.conf"
Now restart the k3s service using following command.
service k3s restart
Delete coredns pod using the following command.
kubectl delete pod $(kubectl get pod -n kube-system | grep coredns | awk '{print $1}') -n kube-system
Run the following command to verify whether the DNS has been updated.
kubectl debug -it $(kubectl get pod -n kube-system | grep coredns | awk '{print $1}') -n kube-system --image=busybox:1.28 --target=coredns -- cat /etc/resolv.conf