MicroK8s setup
Table of contents
For any unresolved issues, check official github repository: https://github.com/ubuntu/microk8s/issues
Install MicroK8s
macOS
Install homebrew, then follow the official document to install microk8s.
if you have issue to start microk8s-vm VM instance, try to turn off VPN installed on host OS, or try to run microk8s uninstall
first, reboot host machine then run microk8s install
again.
Ubuntu Linux
- Install via snap:
sudo snap install microk8s --classic
- Configure Ubuntu ufw firewall settings:
sudo ufw allow in on cni0 sudo ufw allow out on cni0 sudo ufw default allow routed
- Add current user to microk8s user group so can invoke command without sudo:
sudo usermod -a -G microk8s ${USER} sudo chown -f -R ${USER} ~/.kube
Reboot for it took effect.
Windows
MicroK8S installer download URL: https://microk8s.io/microk8s-installer.exe
On Windows, MicroK8s can be run on Hyper-V based VM or VirtualBox based VM. Both of these requires at least 4GB free RAM & 50GB free disk spaces available. On Windows 10/11 Home Edition, you must using VirtualBox approach since Hyper-V is not available on that SKU.
Recommend to install
for better CLI experience.
The fastest way is to install those tools are by “winget” command lines:
winget install --id Microsoft.PowerShell
winget install --id Microsoft.WindowsTerminal
Note:
If your system drive (C:) is less than 50GB free space, you can create symbolic link in PowerShell with Administrator permission, so redirect various configuration and VM image files of multipass saving to another disk drive, for example, the following command make those files save to D:\multipassd
folder:
(Note: you have to create target empty folder D:\multipassd
before running this command.)
gsudo New-Item -ItemType SymbolicLink -Path "C:\Windows\System32\config\systemprofile\AppData\Roaming\multipassd\" -Target "D:\multipassd\"
Hyper-V installation
Note:
If your system drive (C:) available free space is limited, you can manually install Hyper-V first, then open Hyper-V manager to set both Virtual Hard Disks and Virtual Machines configuration files to another drive:
Installation
- Run MicroK8S installer, check
Add 'microk8s' to PATH
, click Install:
- It will prompt to Multipass install wizard, click Next to install:
- Select Microsoft Hyper-V, then click Next:
- Select Add multipass to the current user’s PATH:
- During installation it may show that it needs to reboot to take effect, just click OK:
- Select Reboot now for restarting Windows to enable Hyper-V:
- After reboot, the Multipass tray icon should show it is successfully started:
- Run the installer again, check Add ‘microk8s’ to PATH, click Install:
- It will prompt to configure microK8S VM, click Yes:
- Click Next to accept default VM creation configuration:
Then wait for Linux VM and MicroK8S instance downloading & installation:
Finally, the installer will show MicroK8s for Windows installation completed:
We can start using microk8s on command line window, for example,microk8s status --wait-ready
to check running status:
Configuration
-
Set stable hostname of Hyper-V VM:
By default, Hypver-V VM’s NAT network IP address would change after each time host reboot, So you will unable to use kubectl cli tool of MicroK8s after host computer reboot:
According to this GitHub issue, we can set MicroK8s config file to use hostname instead of IP address to avoid kubectl connection failure:- Login into the MicroK8S VM by:
multipass shell microk8s-vm
- Edit
/var/snap/microk8s/current/certs/csr.conf.template
configuration file (needs to use sudo to edit), add new DNS entries like following:DNS.6 = microk8s-vm.mshome.net
- Restart K8s service:
sudo microk8s.stop; sudo microk8s.start
- Exit MicroK8S VM shell by type
exit
. - Modify MicorK8s configuration file
%LOCALAPPDATA%\MicroK8S\config
on Windows Host side, like following PowerShell command to open that file in Visual Studio Code:code "$env:localappdata\MicroK8S\config"
Replace line 5
https://[private IPv4 address]:16443
’s IP address with domain name microk8s-vm.mshome.net as:server: https://microk8s-vm.mshome.net:16443
- Login into the MicroK8S VM by:
VirtualBox installation
Prerequisite
You have to install VirtualBox & Mulitpass manually, Choose VirtualBox as underlying Hypervisor And Reboot Windows, Run Mulitpass’s “Open Shell” command before run MicroK8S installer, then the installer will be able to start MicroK8s VM correctly.
The most straightforward way to install is by “winget” command line:
- Install VirtualBox:
winget install --id Oracle.VirtualBox
Note: You may need to restart Windows to make VirtualBox virtual network driver took effect. - Install Multipass, be sure to add last
-i
argument for interactive installation:winget install --id Canonical.Multipass -i
During installation wizard, be sure to choose Oracle VirtualBox when ask which Hypervisor to use:
Be sure to select Add multipass to the current user’s PATH option in following install wizard page:
- Run
multipass get local.driver
command to check if Multipass is surely using VirtualBox as underlying Hypervisor, if not, run following command to set VirtualBox as Multipass underlying hypervisor driver in PowerShell with Administrator permission:multipass set local.driver=virtualbox
- Start Multipass application from start menu (Or it has already been auto started by default installation configuration, Right Click then select “Open Shell” from its tray icon:
- Wait for PowerShell window doing 1st time preparation of primary VM of Multipass downloading VM image:
When its done, PowerShell Window will show a Linux Bash has success login status, And the tray icon will show “primary” VM is running, which means Multipass has installed successfully:
Installation
- Run MicroK8S installer, check Add ‘microk8s’ to PATH, click Install:
- Click Yes to start preparing MicroK8s VM:
- Click Next to accept default VM creation configuration:
- Wait for MicroK8s VM downloading & preparation:
Finally, the installer will show MicroK8s for Windows installation completed:
We can start using microk8s on command line window, for example,microk8s status --wait-ready
to check running status:
Configuration
Because the limitation of VirtualBox’s NAT virtual network adapter, to use microk8s kubectl
command, you need to add port mapping to redirect port to host computer:
- Install gsudo
- Open VirtualBox manager GUI as LocalSystem Account by command:
gsudo -s '& "$env:VBOX_MSI_INSTALL_PATH\VirtualBox.exe"'
Add 16643 port forwarding of NAT network adapter 1 of microk8s-vm to host computer: Or you can use following command to do that conveniently without leaving CLI windows:
sudo -s '& "$env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe" controlvm microk8s-vm natpf1 "kubectl_port, tcp,,16443,,16443"'
- Modify MicorK8s configuration file
%LOCALAPPDATA%\MicroK8S\config
on Windows Host side, like following PowerShell command to open that file in Visual Studio Code:code "$env:localappdata\MicroK8S\config"
Replace line 5
https://[private IPv4 address]:16443
’s IP address with 127.0.0.1 like following:server: https://127.0.0.1:16443
Then you will be able to invoke microk8s kubectl
command normally on Windows Host.
Some other configuration notices can be found on official document.