To address missing DNS entries in some VMs, follow the steps below to manually add nameservers and search domain to k3s:

  1. Create a file /etc/rancher/k3s/resolv.conf with the following data.

    vi /etc/rancher/k3s/resolv.conf
    Data:
    nameserver <DNS_IP_1>
    nameserver <DNS_IP_2>
    search <DOMAIN_1> <DOMAIN_2>

  2. Create another file /etc/rancher/k3s/config.yaml with the following data.

    vi /etc/rancher/k3s/config.yaml
    Data:
    kubelet-arg:
      - "resolv-conf=/etc/rancher/k3s/resolv.conf"

  3. Now restart the k3s service using following command.

    service k3s restart

  4. Delete coredns pod using the following command.

    kubectl delete pod $(kubectl get pod -n kube-system | grep coredns | awk '{print $1}') -n kube-system

  5. 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