MicroK8s: getting started with Kubernetes

Kubernetes Logo
Kubernetes Logo

Kubernetes is rapidly gaining traction in the industry. As more and more people start using it, installation methods are also becoming more efficient and newer distributions are born. MicroK8s is an easy way to install and manage a complete Kubernetes cluster created by Canonical. In this article you will learn the main differences between a vanilla cluster and a MicroK8s cluster as well as how to create and manage one.

What is MicroK8s?

MicroK8s is a CNCF-certified Kubernetes distribution from Canonical, the same guys behind Ubuntu. The main difference between a vanilla Kubernetes experience and MicroK8s is the target: MicroK8s packs everything you need for a one-node install or a vast deployment in the same package. You can run MicroK8s directly on any supported Linux distribution and architecture, or you can run it on Windows and Mac OS.

Main features

Let’s take a look at the main features of MicroK8s:

  • Packaged as a snap package: Snapcraft (commonly Snap) is a new-generation package manager made by Canonical. When you install a snap (package) you don’t need to deal with complicated dependencies or missing libraries, the snap contains everything you need in order to run the software you’re installing.
  • Installation is EASY: Kubernetes is an intricate machinations, while installers such as Kubeadm make increasingly easy to install it, it still is pretty difficult, especially for beginners. MicroK8S packs everything you need to get started without hiccups, you won’t need to complete most of the tasks needed to bootstrap a new cluster.
  • Networking out-of-the-box: one of the most important choices when creating a new cluster is which networking plugin to use, project Calico ships by default with MicroK8S, no need to configure anything.
  • Dqlite instead of etcd: etcd is the primary storage for Kubernetes configuration, it is the most important component of a working cluster, without etcd nothing will work. MicroK8s uses Dqlite, a distributed verrsion of SQLite by Canonical, instead of etcd. Dqlite requires less resources compared to etcd, making it particularly interesting for small deployments.
  • High-availability out-of-the-box (since 1.19): when adding 3+ nodes to a MicroK8s cluster HA is enabled by default, the Dqlite backend is automatically configured in a HA fashion without the user even noticing. (It may not look like a great thing if you’re a beginner, but it is!)
  • Add-ons: MicroK8s comes with many add-ons that enhance the cluster capabilities with some of the most popular software such as Istio with a click.
  • Low-footprint: while Canonical doesn’t publish official requirements for MicroK8s, a small installation can run on a pretty low footprint, even on a Raspberry PI.

Getting started with MicroK8s on Linux

In order to get started you will need snapcraft installed. Once you have installed snap you need to select a suitable channel which directly translates to the Kubernetes version you will be using. As of the time of writing this article version 1.19 is the latest stable. You can take a look at the release notes for MicroK8s versions.

DebianUbuntuFedoraCentOSSUSE
$ sudo apt update
$ sudo apt install snapd
$ sudo snap install core
$ sudo snap install microk8s --classic --channel=1.19/stable

On some versions of Ubuntu, Snap comes preinstalled, if it’s not you can use the following commands to install it along MicroK8s:

$ sudo apt update
$ sudo apt install snapd
$ sudo snap install microk8s --classic --channel=1.19/stable
$ sudo dnf install snapd fuse squashfuse
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo snap install microk8s --classic --channel=1.19/stable
$ sudo yum install epel-release
$ sudo yum update
$ sudo yum install snapd
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo systemctl enable --now snapd.socket
$ sudo snap install microk8s --classic --channel=1.19/stable

Be sure to change openSUSE_Leap_15.2 in the repository URL according with your system. E.g. for openSUSE 15.1 use openSUSE_Leap_15.1, for openSUSE Tumbleweed use openSUSE_Tumbleweed

$ sudo zypper addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/openSUSE_Leap_15.2 snappy
$ sudo zypper --gpg-auto-import-keys refresh
$ sudo zypper install snapd
$ sudo systemctl enable --now snapd

## If you're using Tumbleweed also do:
$ sudo systemctl enable --now snapd.apparmor

## Install MicroK8s
$ sudo snap install microk8s --classic --channel=1.19/stable

MicroK8s on Windows and Mac OS

It is possible to install MicroK8s on Windows and Mac OS, albeit it is slightly different than running directly on Linux. On Windows and MacOS a virtual machine will be created and MicroK8s will run on top of it.

Windows

You will need Hyper-V or Virtualbox installed, 4GB of RAM and 40GB of disk space. When you’re ready you can download the installer, once downloaded run it and follow the instructions, you will be asked for general information such as the number of CPUs and RAM amount to allocate to the virtual machine. Once complete you will be able to access the microk8s command as you would on Linux through the command line.

Mac OS

To install MicroK8s on Mac OS you will need “macOS Yosemite, version 10.10.3 or later installed on hardware from 2010 onwards”, 4GB of RAM and 40GB of disk space. You will need homebrew installed.

Mac OS
$ brew install ubuntu/microk8s/microk8s
$ microk8s install

Moving your first steps

MicroK8s can be entirely managed from the command line command “microk8s”. You can use:

  • microk8s start and microk8s stop to manage the services/VM,
  • you can check the status through the microk8s status command.
  • you can use microk8s enable/disable command to enable/disable add-ons.

The main access point for any Kubernetes cluster is the kubectl command, you can access the command through the microk8s kubectl command (write arguments after the command).

If you’re new to Kubernetes I highly suggest you to use the Lens IDE. In order to do so you will need a kubeconfig, you can get the config through microk8s config command.

Image courtesy of mark | marksei
mark

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.