Link Search Menu Expand Document

MicroK8s setup

Table of contents
  1. MicroK8s setup
    1. Install MicroK8s
      1. macOS
      2. Ubuntu Linux
      3. Windows
        1. Hyper-V installation
          1. Installation
          2. Configuration
        2. VirtualBox installation
          1. Prerequisite
          2. Installation
          3. Configuration

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

  1. Install via snap:
    sudo snap install microk8s --classic
    
  2. Configure Ubuntu ufw firewall settings:
    sudo ufw allow in on cni0
    sudo ufw allow out on cni0
    sudo ufw default allow routed
    
  3. 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: Open Hyper-V manager configuration UI

Installation
  1. Run MicroK8S installer, check Add 'microk8s' to PATH, click Install:
    Check Add microk8s to PATH
  2. It will prompt to Multipass install wizard, click Next to install:
    Prompt to install Multipass
  3. Select Microsoft Hyper-V, then click Next:
    Select using Hyper-V
  4. Select Add multipass to the current user’s PATH:
    Check Add multipass to PATH
  5. During installation it may show that it needs to reboot to take effect, just click OK:
    Prompt it needs reboot
  6. Select Reboot now for restarting Windows to enable Hyper-V:
    Select Reboot now
  7. After reboot, the Multipass tray icon should show it is successfully started:
    Multipass started
  8. Run the installer again, check Add ‘microk8s’ to PATH, click Install:
    Check Add microk8s to PATH
  9. It will prompt to configure microK8S VM, click Yes:
    Ask for MicroK8s VM configuration
  10. Click Next to accept default VM creation configuration:
    McroK8s VM creation spec
    Then wait for Linux VM and MicroK8S instance downloading & installation:
    McroK8s VM downloading & installing
    Finally, the installer will show MicroK8s for Windows installation completed:
    McroK8s install completed
    We can start using microk8s on command line window, for example, microk8s status --wait-ready to check running status:
    McroK8s VM creation spec
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:
    kubectl of MicroK8s cannot access after reboot
    According to this GitHub issue, we can set MicroK8s config file to use hostname instead of IP address to avoid kubectl connection failure:

    1. Login into the MicroK8S VM by:
      multipass shell microk8s-vm
      
    2. 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
      

      Edit microK8s config file inside VM

    3. Restart K8s service:
      sudo microk8s.stop; sudo microk8s.start
      

      restart MicroK8S service

    4. Exit MicroK8S VM shell by type exit.
    5. 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
      

      set MicroK8S config file

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:

  1. Install VirtualBox:
    winget install --id Oracle.VirtualBox
    

    Install VirtualBox via winget
    Note: You may need to restart Windows to make VirtualBox virtual network driver took effect.

  2. 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:
    Choose Oracle VirtualBox as Hypervisor Be sure to select Add multipass to the current user’s PATH option in following install wizard page:
    Add Multipass to Path

  3. 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
    

    Set VirtualBox as underlying hypervisor driver for Multipass

  4. 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:
    Open Shell of Multipass
  5. Wait for PowerShell window doing 1st time preparation of primary VM of Multipass downloading VM image:
    Wait 1st time primary
    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: Multipass installed successfully
Installation
  1. Run MicroK8S installer, check Add ‘microk8s’ to PATH, click Install:
    Check Add microk8s to PATH
  2. Click Yes to start preparing MicroK8s VM:
    Ask for MicroK8s VM configuration
  3. Click Next to accept default VM creation configuration:
    McroK8s VM creation spec
  4. Wait for MicroK8s VM downloading & preparation:
    McroK8s VM downloading & installing
    Finally, the installer will show MicroK8s for Windows installation completed:
    McroK8s install completed
    We can start using microk8s on command line window, for example, microk8s status --wait-ready to check running status:
    McroK8s VM creation spec
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:

  1. Install gsudo
  2. 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: Add port 16643 port mapping 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"'
    
  3. 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
    

    set MicroK8S config file

Then you will be able to invoke microk8s kubectl command normally on Windows Host.

Some other configuration notices can be found on official document.