Description
When setting up the local multi-node cluster using Vagrant, the VMs lose domain name resolution (DNS). Commands like apt-get update or ping google.com fail to resolve, even though raw internet access via IP address still works (e.g., ping 8.8.8.8 succeeds).
Why this happens
When Vagrant configures the network interface required for internal Kubernetes traffic, the OS network scripts overwrite the DNS settings originally provided by the primary NAT internet adapter. Because the private network has no DNS server assigned, the VMs are left with an empty or broken configuration.
The Fix
To prevent this, your Vagrantfile needs to be configured to force VirtualBox (or any virtualization software you use) to proxy the host machine's DNS down to the guest.
Updating the machines.each block in the vagrantfile to include these settings permanently fixes the issue:
machines.each do |name, specs|
config.vm.define name do |machine|
machine.vm.hostname = name
machine.vm.network "private_network",
ip: specs[:ip]
machine.vm.provider "virtualbox" do |virtualbox|
virtualbox.name = "kthw-#{name}"
virtualbox.cpus = 1
virtualbox.memory = specs[:memory]
# Force VirtualBox to proxy host DNS directly to the VM
virtualbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
virtualbox.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
# Force a public fallback DNS inside the guest OS config file
machine.vm.provision "shell", inline: <<-SHELL
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
SHELL
end
end
Note: The forcing of a public nameserver during the shell provisioning step is optional. I added it to double check.
Description
When setting up the local multi-node cluster using Vagrant, the VMs lose domain name resolution (DNS). Commands like
apt-get updateorping google.comfail to resolve, even though raw internet access via IP address still works (e.g.,ping 8.8.8.8succeeds).Why this happens
When Vagrant configures the network interface required for internal Kubernetes traffic, the OS network scripts overwrite the DNS settings originally provided by the primary NAT internet adapter. Because the private network has no DNS server assigned, the VMs are left with an empty or broken configuration.
The Fix
To prevent this, your
Vagrantfileneeds to be configured to force VirtualBox (or any virtualization software you use) to proxy the host machine's DNS down to the guest.Updating the
machines.eachblock in the vagrantfile to include these settings permanently fixes the issue:Note: The forcing of a public nameserver during the shell provisioning step is optional. I added it to double check.