Cloud Native / Kubernetes

Exploring Microk8s, the Lightweight Kubernetes Distribution from Canonical

4 Dec 2020 10:28am, by

Microk8s is a small, lightweight, and fully conformant Kubernetes distribution from Canonical. It’s a minimalistic distribution focused on simplicity and performance. Given its footprint, Microk8s can be easily deployed in IoT and edge devices.

Canonical has packaged Microk8s as a snap, the company’s package manager for Linux. A snap is a bundle of an app and its dependencies that works without modification across many different Linux distributions. Snaps are independent, self-contained applications that run in a sandbox with mediated access to the host system. Snaps have emerged as an alternative to the standard .deb packages typically used in Debian-based distributions. Applications packaged as a snap can be easily installed and uninstalled.

Apart from the recent versions of Ubuntu, snaps can be deployed on a variety of platforms, including Linux Mint, Raspberry Pi OS, and Arch Linux.

Since Microk8s is based on snap, it can be easily deployed with a single command. For example, on Ubuntu 18.04, sudo snap install microk8s --classic installs a fully functional, single-node Kubernetes cluster. The installation procedure is the same with any platform running snapd, the daemon for the snap package manager:

It is also possible to install Microk8s in an air-gapped, offline environment by downloading the snap and installing it. The self-contained snap file is approximately 200MB in size:

Running Microk8s on macOS

Microk8s can be installed on macOS and Microsoft Windows through Multipass — the virtual machine manager from Canonical. Multipass takes advantage of the underlying hypervisor such as Hyper-V in Windows and hyperkit in macOS.

The Microk8s CLI abstracts the commands involved in creating the VM and installing the snap. With Homebrew installed, the commands below launch a single node Microk8s on macOS:

If you want to understand the workflow involved, try the below commands to install Multipass followed by Microk8s:

Wait till the VM is created and then SSH into it:

Continue with the installation of Microk8s:

Configure the VM and generate the kubeconfig file:

To access the single node cluster from the host, let’s copy the kubeconfig file:

You can now access Microk8s from macOS with kubectl.

Extending Microk8s Functionality with Addons

To keep the deployment footprint small, Microk8s comes with the most essential components related to the control pane. That means the default installation doesn’t have storage and network plugins, DNS, Kubernetes dashboard, and other expected components.

Canonical has added many components as optional add-ons to Microk8s. They can be enabled and disabled through the microk8s enable/disable command.

For example, the Kubernetes dashboard can be added with just one command. If you are running Microk8s in a Multipass VM, run the below command from the shell:

Get the default token associated with the service account to access the dashboard:

Access the dashboard with the below command from the host:

Configuring and Deploying a Highly Available Microk8s Cluster

Recently, Canonical has added high availability to Microk8s to make it production-ready. When at least three nodes are deployed, Microk8s automatically scales out the control plane to run the API services on more than one node.

In a typical High Availability (HA) deployment scenario, etcd is used as the key/value database to maintain the state of the cluster. Microk8s uses Dqlite, the distributed version, and a highly available version of SQLite.

All that is required for HA MicroK8s is three or more nodes in the cluster, at which point Dqlite is automatically highly available. If the cluster has more than three nodes, then additional nodes will be standby candidates for the datastore and promoted automatically if the datastore loses one of its nodes. The automatic promotion of standby nodes into the voting cluster of Dqlite makes MicroK8s HA autonomous and ensures that quorum is maintained even if no administrative action is taken.

In the next part of this tutorial, I will walk you through the steps of deploying a highly available Microk8s cluster in a bare-metal environment. We will explore storage and networking configuration to run stateful workloads.

I am also planning to do a detailed comparison of lightweight Kubernetes distributions in the market — Microk8s, K3s, and K0s. Stay tuned!

Janakiram MSV’s Webinar series, “Machine Intelligence and Modern Infrastructure (MI2)” offers informative and insightful sessions covering cutting-edge technologies. Sign up for the upcoming MI2 webinar at

Feature image by Mario Aranda de Pixabay

A newsletter digest of the week’s most important stories & analyses.