Install a local Kubernetes with Microk8s

Getting started with Microk8s

Single-node deployments of Kubernetes are more common than one would expect. In some scenarios, single-node clusters make much more sense. For development or testing purposes, there’s no need to deploy a full production cluster.

So, to solve this trouble, we have MicroK8s, a tool by Canonical. In this hands-on lab, we will be going to learn about MicroK8s, and also we will see how to set them up on our machine.

About MicroK8s

MicroK8s is an open-source system for automating deployment, scaling, and management of containerized applications. It enables you to easily deploy a lightweight single-node cluster in your local environment

But now the question is, doesn’t Minikube already allow us to do just this? Yes, Minikube also allows us to deploy a single-node Kubernetes cluster locally but with one key difference — it’s VM-based, and thus will work best running within a VM, primarily on Mac and Windows but also on Linux. 

MicroK8s, on the other hand, was designed for Linux and do not require a VM. Instead, it can easily be installed as a snap package using one simple command. Because it doesn’t require a VM, there are more resources available on the given machine to run applications, which makes MicroK8s a perfect fit for edge installations.

MicroK8s: Why use it

It provides the functionality of core Kubernetes components, in a small footprint, scalable from a single node to a high-availability production cluster. However, MicroK8s is aiming to reduce entry barriers for K8s and cloud-native application development.

There are some of the key reasons to use it widely.

  • Delivered as snap packages – App packages for desktop, cloud, and IoT that are easy to install and secure with auto-updates, which support snaps.
  • Production-grade add-ons —  IstioKnativeCoreDNSPrometheusJaegerLinkerdCilium, and Helm are available as add-ons and yet are simple to set up.
  • Strict confinement – Ensures complete isolation from the underlying operating system and a tightly secured production-grade Kubernetes environment.

Installation

As we triggered the lab through the LAB SETUP button, a terminal, and an IDE comes for us. MicroK8s snap can be installed using the below command:

snap install microk8s --classic

The above command will install MicroK8s in a snap and within a few seconds, you should see this message displayed:

Now, confirm the status of MicroK8s by running the following command:

microk8s status

We can see a long list of available addon components that are disabled and the ones currently enabled which we will discuss in the next step.

Enable addons

To make MicroK8s as lightweight as possible, the default installation includes a core Kubernetes deployment, which includes the api-server, controller-manager, scheduler, kubelet, cni, and kube-proxy.


For the sake of demonstration in this hands-on lab, we’ll add the dashboard addon that provides the well-known user interface to monitor and operate Kubernetes clusters. We’ll also enable two other addons that will support the dashboard — dns and storage

microk8s enable dns dashboard storage

These add-ons can be disabled at any time by running the microk8s disable command:

microk8s disable dns dashboard storage


We can have a look at some of the most important addons.

  • dns: Deploy DNS. This addon may be required by others, thus we highly recommend you always enable it.
  • dashboard: Deploy Kubernetes dashboard.
  • ingress: Create an ingress controller.
  • storage: Create a default storage class. This storage class makes use of the hostpath-provisioner pointing to a directory on the host.
  • registry: Deploy a docker private registry and expose it on localhost:32000. The storage addon will be enabled as part of this addon.

Host your first service in Kubernetes

We start by creating a microbot deployment with two pods via the kubectl cli:

microk8s kubectl create deployment microbot --image=dontrebootme/microbot:v1
microk8s kubectl scale deployment microbot --replicas=2

To expose our deployment we need to create a service:

microk8s kubectl expose deployment microbot --type=NodePort --port=80 --name=microbot-service

As we have deployed this service on a 30000 node port, you need to change. Run the following command which will open up a yaml file of the microbot-service . 

microk8s kubectl edit svc microbot-service

Now, check the microbot-service running in default namespace to verify that it is running on port 30000 .

microk8s kubectl get svc -n default

At this moment, the microbot-service can be accessed through the app-port URL under the Lab-URLs section.

To see what the cluster looks like, run the following command:

microk8s kubectl get all --all-namespaces 

It takes a few minutes to get all pods in the “Running” state.

Join Our Newsletter

Share this article:

Table of Contents