Install K3S on ubuntu multipass with ansible on Win10 + Virtualbox

Daniele De Francesco
6 min readMar 14, 2021

A couple of weeks ago, with some colleagues of mine, I was involved in a study on making a workshop about Ansible technology for technical training in our company. The problem was raised of how to make the students use the laboratory attached to the workshop: some (like me) were of the idea to use Vagrant: it’s the reference VM builder and manager for Ansible local hosted training, after all; other colleagues came up with Multipass VM manager from Canonical, saying it could have been easier to install and run on an average Windows10 PC of ours.

So, I knew about Multipass. And here come the issues…

Setup Multipass on an old Windows10 machine (before 2018).

Multipass it’s a great tool, I mean quite great, but it’s development stage it’s still in “infancy” and the virtualization technology on which it’s based upon (on Windows 10 at least) is the best of breed available today: HyperV 2. After all, who has a company development pc than before 2018? Me, of course.

So in Multipass installation wizard, the only choice that I had was to use Oracle Virtualbox…now, from Multipass.run site:

“Note: You need Windows 10 Pro/Enterprise/Education v 1803 or later, or any Windows 10 with VirtualBox. Make sure your network is private or Windows prevents Multipass from starting. Run the installer. You need to allow the installer to gain Administrator privileges.

By now, it should be clear why I’ve written this guide: because I’m on an old 2017 Win10 Enterprise pc, and, yes, I don’t think HyperV is very popular between IT guys. You see, Multipass has a limited (not to say poor) Virtualbox Hypervisor support against NAT networking which in turn works like a charm with HyperV 2. This flaw is the cause that compelled us to configure a BRIDGED Adapter to assign a dhcp address to every instance; without this configuration, every Multipass VM created on Virtualbox, as you can understand, is isolated from the others.

K3S Cluster Installation on Multipass

This configuration can be made only once the Multipass VMs are created. So let’s dive in the creation of K3S cluster:

Create node + master

With Multipass installed run the usual

multipass launch --name k3s-master --cpus 1 --mem 1024M --disk 3Gmultipass launch --name k3s-node1 --cpus 1 --mem 1024M --disk 3Gmultipass launch --name k3s-node2 --cpus 1 --mem 1024M --disk 3G

Multipass will provide you with the requested VMs and now…

Configure Virtualbox Bridged Adapter (Win10 + VBox)

Let’s come to the hot issue that Canonical is not going to tackle, at least in the short term.

Use Case → It’s not possible/desirable use HyperV on Win10

The problem → Virtualbox hypervisor VM dhcp cannot assign ip address through NAT adapter

In fact, as can be seen by the output of the list command the column IPv4 is ‘not assigned

PS C:\WINDOWS\system32> multipass listName       State  IPv4 Imagek3s-master Running N/A Ubuntu 20.04 LTSk3s-node1  Running N/A Ubuntu 20.04 LTSk3s-node2  Running N/A Ubuntu 20.04 LTS

Well, first of all, let me thank Jon Sprig blog for having given me the right and ( as far as I’m aware of ) only procedure that makes Multipass VMs work on Virtualbox Hypervisor as machines that are connected together.
The steps to fulfill the procedure are:

  1. Download PsTools → Unzip PsTools → Add bin path in %Path% (administrator)
  2. Stop VM
  3. Modify VM → Add Bridged Adapter
  4. Start VM → Open Shell
  5. Verify NEW ip link is DOWN
  6. Add Netplan config file
  7. Apply Netplan configuration
  8. Confirm ip link is UP

So for every VM:

PS> multipass stop k3s-<node>PS> Get-NetAdapter -Physical | format-list -property “Name”,”DriverDescription”Name : Ethernet
DriverDescription : Intel(R) Ethernet Connection (4) I219-LM
Name : Wi-Fi
DriverDescription : Intel(R) Dual Band Wireless-AC 8265
PS> PsExec64.exe -s vboxmanage modifyvm k3s-<node> --nic2 bridged — bridgeadapter2 “Intel(R) Dual Band Wireless-AC 8265”PS> PsExec64.exe -s vboxmanage showvminfo k3s-<node>NIC 1: MAC: 525400B90F6D, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: noneNIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)NIC 1 Rule(0): name = ssh, protocol = tcp, host ip = , host port = 61308, guest ip = , guest port = 22NIC 2: MAC: 080027A88E02, Attachment: Bridged Interface ‘Intel(R) Dual Band Wireless-AC 8265’, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: nonePS> multipass start k3s-<node>PS> multipass shell k3s-<node>$ ip link → Verify link enp0s8 is DOWN$ sudo nano /etc/netplan/60-extra-interfaces.yamlnetwork:
ethernets:
enp0s8:
optional: yes
dhcp4: yes
dhcp4-overrides:
route-metric: 10
ctrl-x -> y -> return$ sudo netplan apply$ ip link → Confirm link enp0s8 is UP$ exitPS C:\WINDOWS\system32> multipass listName State IPv4 Imagek3s-master Running 192.168.1.10 Ubuntu 20.04 LTSk3s-node1 Running 192.168.1.20 Ubuntu 20.04 LTSk3s-node2 Running 192.168.1.21 Ubuntu 20.04 LTS

And voilà…we have 3 brand new local LAN network IPs.

Install ansible and git on master node

With VMs in place, started and finally reachable on local net, let’s get console access to k3s-master:

PS C:\WINDOWS\system32> multipass shell k3s-master

Then, update, upgrade VM, install ansible and git and clone K3S ansible installation repository.

$ sudo apt update && sudo apt -y upgrade$ sudo apt install ansible git$ ansible --version$ git clone https://github.com/k3s-io/k3s-ansible.git

Ansible setup

Modify /etc/hosts file on every host so that we can refer to other VMs by hostname in configurations

Es. on k3s-master with an editor of your choice write down hosts mapping

192.168.1.10 k3s-master192.168.1.20 k3s-node1192.168.1.21 k3s-node2

Enable password access login

Modify sshd configuration on all nodes for password login. Needed for ssh access in public key exchange (see below).

$ sudo nano /etc/ssh/sshd_configPasswordAuthentication yes$ sudo systemctl restart sshd

Change ansible user password (needed for multipass)

Multipass creates Ubuntu VM instances with one passwordless sudoer named ubuntu. So we enabled password login and now we’re giving ubuntu user a password.

$ sudo passwd ubuntuNew password: <supersecret>Retype new password: <supersecret>passwd: password updated successfully

SSH key exchange

From k3s-master issue the command

$ ssh-copy-id -i .ssh/id_rsa.pub ubuntu@k3s-<node>

to exchange ssh public key between nodes (more on ssh key generation here)

Disable password access login

Put back previous sshd configuration to get Ansible reach all configured hosts

$ sudo nano /etc/ssh/sshd_configPasswordAuthentication no$ sudo systemctl restart sshd

Ansible inventory setup

Now let’s setup Ansible inventory (hosts.ini) file like this:

$ cd k3s-ansible/inventory/
$ cp -r sample k3s-cluster
$ cd k3s-cluster
$ nano hosts.ini
[master]
k3s-master
[node]
k3s-node1
k3s-node2
[k3s_cluster:children]
master
node

Execute Ansible Playbook

Now from the root directory of the git repository we’ve cloned earlier, run the command

$ ansible-playbook site.yml -i inventory/k3s-cluster/hosts.ini

All will be fine..and eventually you will see something like this:

PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************k3s-master : ok=20 changed=12 unreachable=0 failed=0 skipped=12 rescued=0 ignored=0k3s-node1 : ok=9 changed=3 unreachable=0 failed=0 skipped=12 rescued=0 ignored=0k3s-node2 : ok=9 changed=3 unreachable=0 failed=0 skipped=12 rescued=0 ignored=0

The item failed=0 beside every VM instance, confirms all the process finished correctly.

If you, like me, have taken the option of installing Ansible on k3s-master you’re done, otherwise you have to copy .kube directory from your other VM (Ansible Master)

Finally try to give the cluster a go

ubuntu@k3s-master:~$ sudo kubectl get allNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 13mubuntu@k3s-master:~$ sudo kubectl get nodesNAME       STATUS ROLES  AGE VERSIONk3s-master Ready  master 14m v1.17.5+k3s1k3s-node2  Ready  <none> 14m v1.17.5+k3s1k3s-node1  Ready  <none> 13m v1.17.5+k3s1ubuntu@k3s-master:~$

And yes…we’re done and you’re the lucky owner of a kubernetes ( k3s distro ) cluster on your Win10 pc, with Canonical Multipass.run AND Virtualbox 6.

--

--