Setting up a Kubernetes cluster with MicroK8s

Published at 25 Apr 2025

MicroK8s allow us to deploy, scale and manage a Kubernetes cluster simplifiying the process. We can use it from a single node cluster to a high-availability production cluster. It's developed by Canonical so we will need an Ubuntu environment or another operating system which supports snapd.

I will be using a machine with Ubuntu server 24.04 LTS.

Install MicroK8s

To install the latest MicroK8s version we should execute the following command:

sudo snap install microk8s --classic

Join the group

MicroK8s creates the microk8s groups which allows the users to manage the cluster. To join our user to the group we should run these commands:

sudo usermod -a -G microk8s $USER
mkdir -p ~/.kube
chmod 0700 ~/.kube

Remember to re-enter the session to update the session information.

su - $USER

Check the status

As we already run the command to install MicroK8s, it's bootstraping all the services required in the background, we can check the status with the --wait-ready flag to wait for the services to initialise.

microk8s status --wait-ready

Access Kubernetes

MicroK8s bundles its own version of kubectl to monitor and control the cluster.

We can list the nodes:

microk8s kubectl get nodes

Or the services:

microk8s kubectl get services

If your system doesn't have installed the standalone kubectl command, you can add an alias to make it easier to run, appending the following to ~/.bash_aliases.

alias kubectl='microk8s kubectl'

Deploy an app

Let's deploy a sample app to make sure the cluster is working as expected:

microk8s kubectl create deployment nginx --image=nginx

After a few seconds the deployment will have created a new pod:

microk8s kubectl get pods

Use add-ons

MicroK8s offer us a bunch of add-ons that offer extra capabilites for cluster, like DNS management, different types of storage, among others.

Let's enable the DNS management and the local storage on the host:

microk8s enable dns
microk8s enable hostpath-storage

You can learn more about these add-ons on the official documentation https://microk8s.io/docs/addons.

Starting and Stopping MicroK8s

MicroK8s will continue to run until you decide stop it with all its services:

microk8s stop

To start it again you can run:

microk8s start

If you leave MicroK8s running, it will automatically restart after a reboot.