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 --classicJoin 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 ~/.kubeRemember to re-enter the session to update the session information.
su - $USERCheck 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-readyAccess Kubernetes
MicroK8s bundles its own version of kubectl to monitor and control the cluster.
We can list the nodes:
microk8s kubectl get nodesOr the services:
microk8s kubectl get servicesIf 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=nginxAfter a few seconds the deployment will have created a new pod:
microk8s kubectl get podsUse 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-storageYou 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 stopTo start it again you can run:
microk8s startIf you leave MicroK8s running, it will automatically restart after a reboot.