Sunday, July 07, 2024

Multipass + MicroK8s on Windows

Multipass is used to create the Ubuntu 24.04 VM on Windows. From here, the VM can be used to install and run MicroK8s.

Steps

  1. Prerequisite - Enable VT
  2. Install Multipass, create VM
  3. Install MicroK8s in the VM
  4. Setup SSH
  5. Extra

Prerequisite - Enable VT

Enable it from the BIOS.

Install Multipass, create VM

Get the installer here.

Skip the creation of a new VM during setup.

Add Multipass 'bin' folder into 'Path' environment variable.

Open Terminal app.

Type the following to identify the network types available:
multipass networks

Name           Type     Description
Default Switch switch   Virtual Switch with internal networking
Ethernet       ethernet Realtek PCIe GBE Family Controller

To get the new VM to 'attach' to the host network and get an IP to your home LAN, note the 'ethernet' type's name (case-sensitive).

Type the following to create a new VM with sufficient resources as recommended by MicroK8s documentation (all in one line):
multipass launch lts --name microk8s-vm --memory 4G --disk 50G --cpus 2 --network name=Ethernet
where
  • lts - VM template/blueprint name for Ubuntu 24.04
  • network - the network type to use, here it's 'Ethernet', Multipass will create a virtual switch automatically, the new entry can be seen by typing 'multipass networks' post-VM creation.
After VM creation, you can access the shell via the system tray icon of Multipass after starting the VM via the context menu.

Install MicroK8s in the VM

Steps below are based on official docs.

At the VM shell, install net-tools:
sudo apt install net-tools
Then use 'ifconfig' to check if the VM has been assigned a LAN IP.

Use the following command to install MicroK8s:
sudo snap install microk8s --classic --channel=1.30/stable
Check if the installation is done:
microk8s status --wait-ready
Add current user (ubuntu) into 'microk8s' group:
sudo usermod -a -G microk8s $USER
mkdir -p ~/.kube
chmod 0700 ~/.kube
Create/update file .bash_aliases with this line:
alias kubectl='microk8s kubectl'
Save the file.

Setup SSH

If you want to access the VM with MicroK8s on another machine, then follow the steps below.

At the VM shell, install OpenSSH:
sudo apt install openssh-server
Edit file /etc/ssh/sshd_config.d/60-cloudimg-settings.conf, adding the following option:
PasswordAuthentication yes
This is to enable password logins just to make things simpler. Set a password for 'ubuntu' also:
sudo passwd ubuntu
Restart SSH service:
sudo systemctl restart ssh

Extra

If enabled the microk8s dashboard and facing TLS errors, try this command:
sudo microk8s refresh-certs --cert ca.crt

No comments: