DEV Community

Cover image for Setting up a Kubernetes cluster with MicroK8s
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

Setting up a Kubernetes cluster with MicroK8s

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

su - $USER
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Access Kubernetes

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

We can list the nodes:

microk8s kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Or the services:

microk8s kubectl get services
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

microk8s kubectl get pods
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To start it again you can run:

microk8s start
Enter fullscreen mode Exit fullscreen mode

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

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay