Vagrant setup for a k3s cluster with a single server and one worker (aka agent) using the libvirt provider
This setup creates a k3s server VM and one VM as k3s agent (aka worker) and installs k3s using Ansible.
Default OS is openSUSE Leap 15.2, but that can be changed in the Vagrantfile.
- You need vagrant obviously.
- Fetch the box, per default this is
opensuse/Leap-15.2.x86_64
, usingvagrant box add opensuse/Leap-15.2.x86_64
. - Make sure the git submodules are fully working by issuing
git submodule init && git submodule update
- Run
vagrant up
- Run
kubectl --kubeconfig ansible/k3s-kubeconfig get nodes
and you should see your server and agent nodes. - Party!
In case you do not want Ansible to install k3s (because you want to install it yourself), just comment out the following lines in the Vagrantfile
:
node.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.limit = "all"
ansible.groups = {
"k3sservers" => [ "k3sserver" ],
"k3sagents" => [ "k3sagent1" ]
}
ansible.playbook = "ansible/playbook-vagrant.yml"
end # node.vm.provision
When tearing down the machine, the kubeconfig and token files that was download does not get deleted unfortunately.
To not cause problems the next time you start, just run rm ansible/k3s-kubeconfig ansible/k3s-token
and all is well.
You can modify the Vagrantfile to create additional agent nodes by tweaking two lines.
- Setting the number of agents (in this example to
2
):
###################################################################################
# define number of agents
W = 2
- Adding the additional agent nodes to the
ansible_groups
line:
ansible.groups = {
"k3sservers" => [ "k3sserver" ],
"k3sagents" => [ "k3sagent1", "k3sagent2" ]
}