Jump to main content

Install MicroK8s on WSL2

Install MicroK8s on WSL2

The Windows Subsystem For Linux Version 2 (also known as WSL2) supports running Ubuntu with systemd as the init process. This enables running snap (and MicroK8s!) natively on Windows hosts.

  1. Install WSL2 on your machine following the instructions from Microsoft. Ensure that the installation completed successfully. Troubleshooting issues around WSL2 are beyond the scope of this document, but you will find lots of information on the WSL2 link above if you run into problems.

  2. Update WSL to the latest version and ensure WSL2 is set as the default version:

    wsl --update
    wsl --set-default-version 2
    
  3. Install Ubuntu and wait for the machine to come up. Configure your username and password for the Ubuntu instance. Below, we choose username ubuntu:

  4. Enable systemd by running the following command in the WSL terminal:

    echo -e "[boot]\nsystemd=true" | sudo tee /etc/wsl.conf
    

    Screenshot_20230130_025228

  5. Exit the WSL terminal, then restart WSL.

    wsl --shutdown
    wsl
    

From this point, systemd is enabled and snaps should work properly. You can list the installed snaps with

sudo snap list
  1. Install MicroK8s.

    sudo snap install microk8s --classic
    

  2. Wait for MicroK8s to start.

    sudo microk8s status --wait-ready
    

    We can also verify that our node is using the WSL2 kernel with:

    sudo microk8s kubectl get node -o wide
    

  3. Enable services and start using Kubernetes!

    MicroK8s with a number of powerful addons out of the box. Enable the functionality you want to get started:

    sudo microk8s enable dns
    sudo microk8s enable storage
    sudo microk8s enable dashboard
    

    To access the dashboard, MicroK8s offers a helper command:

    sudo microk8s dashboard-proxy
    

    Open a browser window to the URL shown in the text and use the token to login:

    MicroK8s wraps the kubectl binary, and you can use it to interact with the cluster:

    sudo microk8s kubectl create deploy --image nginx --replicas 3 nginx
    

What next?

Last updated 1 year, 7 months ago. Help improve this document in the forum.