You need to enable Javascript to enjoy the finer things in life... ;)

Setting up MicroK8s on Ubuntu 22.04 LTS

MircoK8s is the native offering by Ubuntu for deploying a production ready Kubernetes cluster on the local environment.

In this tutorial, we will cover the following topics:

  1. Installing snapd as a prerequisite.
  2. Installing microk8s
  3. Setting up microk8s
  4. Setting up network firewall using ufw
  5. Setting up addons

Installing snapd

snapd is the preferred way to install applications natively on ubuntu, according to the “ubuntu devs”. I say “ubuntu devs” because I think they are the only ones who like it. Most people don;t prefer snapd.

Anyways, snapd can be install by executing the following command:

sudo apt install snapd

Installing microk8s

MicroK8s can be installed by using the following command:

sudo snap install microk8s --classic --channel=latest/stable

The channel can be changed into any preferred versions or channels to install microk8s.

The microk8s instance has been installed. Yup. It was that easy. Now comes the hard part (comparatively).

Setting up microk8s

First step here would be to try out the basic tools for managing the cluster.

microk8s

The microk8s command can be used to manage the cluster. The following command outputs the status of the cluster.

sudo microk8s status

The cluster can be started by using the following command:

sudo microk8s start

The cluster can be stopped by using the following command:

sudo microk8s stop

microk8s kubectl

The kubectl tool is used to manage the cluster at granular level. This is the tool, we will be using the most. The usage can be found at: https://kubernetes.io/docs/reference/kubectl/

The first thing that we’ll do is to add this as an alias so that we don’t have to type “microk8s kubectl” everytime. As I said, this tool is the most used when managing our cluster.

We will just add the following line to the end of ~/.bashrc file:

alias kubectl='microk8s kubectl'

Restart your by either logging out and logging back in, or, just type the following to reload your bash configuration:

source ~/.bash

The following command can be used to check that the main k8s services and pods are up and running:

sudo kubectl -n kube-system get all

microk8s helm3

The helm3 tool is used to deploy helm charts in the cluster. It is also included with microk8s. As before add the following line to the ~/.bashrc file:

alias helm='microk8s helm3'

Now reload the session using the following command:

source ~/.bash

The usage for helm tool can be found at: https://helm.sh/docs/intro/using_helm/

Setting up the network firewall using ufw

If we are using Ubuntu, chances are we are using the ufw firewall tool that comes bundled with Ubuntu 22.04. We would need to enable the following rules for enabling communication and internet access in pods:

sudo ufw allow in on vxlan.calico && sudo ufw allow out on vxlan.calico
sudo ufw allow in on cali+ && sudo ufw allow out on cali+

Now, we can just reload the firewall using the following command:

sudo ufw reload

And, we are done!!

Setting up addons

We can check the list of available addons by executing the following command:

sudo microk8s status

To enable dashboard addon, we can use the following command:

sudo microk8s enable dashboard

Persistence data addon is disabled by default as we are generally recommended to not use the local host. But, for single node cluster, it doesn’t make sense to waste money on S3 buckets. To enabled local host persistence storage, we can use the following command:

sudo microk8s enable hostpath-storage

Generally when using helm charts, the deployment will automatically use the hostpath-storage class unless mentioned otherwise.

Now we can use the following command to check for persistent volumes (if present):

sudo kubectl get pvc

Final Thoughts

MircoK8s is now fully up and running in our Ubuntu machine. I could get into more advanced kubernetes concepts in the future. Let’s see.

Leave a Comment

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