Post Image

Kubernetes Microk8s Create HA Cluster

Microk8s brings you a quick and easy way to get started with kubernetes and as long as you have a few machines on your network, you can have a fully functional kubernetes cluster configured in HA operational in under 10 minutes. In this post I will show you the steps to setup a kubernetes cluster on Ubuntu 22.04.

 

Install microk8s

On all nodes you want in the cluster run the following command to install microk8s.

$ sudo snap install microk8s --classic

Next give your user account access to execute the microk8s command and refresh the permissions so you dont need to re login.

$ sudo usermod -a -G microk8s <username>
$ newgrp microk8s

At this point you have microk8s installed on all of your machines in standalone mode, so if you wanted you could spin up a deployment on any one of your machines.

 

Cluster your Nodes

With microk8s it is just as easy to join all of your nodes into a cluster as it was to install kubernetes. First you will want to pick a node that will for sure be a control plane node, and for this purpose we will assume it is node 1 in the cluster. To be clear it does not NEED to be node 1 because its not like this node is the sole node to control the cluster however its just easier to keep things simple.

On node 1 run the following command

Node1$ microk8s add-node
From the node you wish to join to this cluster, run the following:
microk8s join 10.204.255.10:25000/stringomitted/stringomited

Use the '--worker' flag to join a node as a worker not running the control plane, eg:
microk8s join 10.204.255.10:25000/stringomitted/stringomited --worker

If the node you are adding is not reachable through the default interface you can use one of the following:
microk8s join 10.204.255.10:25000/stringomitted/stringomited
Node1$

This will spit out the command you need to paste into one of the other nodes in order to join it to the cluster. Because we want an HA cluster we will use the first microk8s join command, if we use the second command the node you add will not be running the control plane and will not contribute to the HA of the cluster.

On the worker node paste in the first join command from node 1.

Node2$ microk8s join 10.204.255.10:25000/outputomitted/outputomitted
Contacting cluster at 10.204.255.10
Waiting for this node to finish joining the cluster. .. .. ..
Node2$

At this point node 2 is added into your cluster.

To add the third node you will need to go back to node 1 and re issue microk8s add node so you get another unique join command and paste it into node 3. You will need to repeat those steps for as many nodes as you want to join to your cluster.

 

After you add the 3rd node on any of the 3 nodes enter the following command to see the HA status

$ microk8s status
microk8s is running
high-availability: yes
  datastore master nodes: 10.204.255.10:19001 10.204.255.11:19001 10.204.255.12:19001
  datastore standby nodes: none
~Output Truncated~
$

At this point you have a fully functioning microk8s kubernetes cluster that you can deploy your applications to. It is not very polished at this point because we have not added any services so at this time you can add whatever services you need like metallb, dns, rbac, ingress, dashboard etc.

 

An example of adding dns and ingress is below

$ microk8s enable dns ingress

 

And thats it, with just a couple commands microk8s allows you to have a cluster configured in HA ready to deploy containers to. If you have any questions please leave a comment below so I can clear up any confusion.



Comments (0)
Leave a Comment