Jack Wallen shows you how to deploy a simple two-node Kubernetes cluster in minutes with the help of microk8s.
Getting a Kubernetes cluster up and running can be a real challenge. This has been made even more apparent after the developers dropped support for the Docker runtime engine. Because of that, you might find the need to spin up a quick development cluster and don’t want to jump through all the new hoops to make it so.
Fortunately, there’s microk8s, which makes it very easy to create a small Kubernetes cluster with just a few quick commands.
SEE: Hiring kit: Back-end Developer (TechRepublic Premium)
I’m going to show you just how easy it is to do this very thing. It should take you less than five minutes to get this cluster up and running.
What is microk8s?
Microk8s was developed by Canonical to serve as a CNCF-certified upstream Kubernetes deployment tool that makes it very simple to deploy a single node or multi-node cluster. One thing to keep in mind, however, is that microk8s is not a replacement for a full-blown Kubernetes cluster. Instead, this tool should be considered specifically for development purposes and not for production deployments.
Microk8s makes it very easy to start working with Kubernetes development and can be quickly installed via snap.
What you’ll need
The only things you’ll need to get this up and running are two Linux machines that support Snap packages (such as Ubuntu) and a user with sudo privileges. I’ll be demonstrating with two virtual machine instances of Ubuntu Server 22.04.
Let’s get to the Kubernetes magic.
How to set your hostnames
Before we install microk8s, let’s set our hostnames. We’ll set the controller to microk8s1 and the node to microk8s2. To do this, log into your controller and issue the command:
sudo hostnamectl set-hostname microk8s1
Log out and log back in.
Do the same thing on the node, changing the name to microk8s2.
Next, you’ll need to add entries for each in the hosts file. Open that file on the controller with the command:
sudo nano /etc/hosts
In that file, you’ll add two entries that look like this — making sure to edit the entries to suit your IP address scheme and domains:
192.168.1.135 microk8s.monkeypantz.lan microk8s1
192.168.1.137 microk8s.monkeypantz.lan microk8s2
Do the same thing on the node.
How to install microk8s
The first thing we must do is install microk8s on both machines. Log into your first machine and install the software with the command:
sudo snap install microk8s --classic
Once the installation completes, you’ll need to add your user to the microk8s group with the command:
sudo usermod -aG microk8s $USER
Next, create a .kube directory with:
Give the new directory the necessary permissions with:
sudo chown -f -R $USER ~/.kube
Log out and log back in.
You can then test the install with the command:
You should see in the output something like this:
microk8s is running
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
Do the same thing with the second machine.
How to join the nodes
On the machine that will serve as your controller, issue the command:
The output of the above command should include the join command that looks like this:
microk8s join 192.168.1.135:25000/f8f7c8b64ed411cf54a8307cead84e73/e0a27e14e027
Run the join command on your second node. Once the command completes, you can verify the connection on the original node with the command:
microk8s kubectl get nodes
The output of the command should show both nodes are a part of the cluster with output that looks like this:
microk8s1 Ready <none> 9m46s v1.24.3-2+63243a96d1c393
microk8s2 Ready <none> 15s v1.24.3-2+63243a96d1c393
One thing to keep in mind is if you need High Availability added to your Kubernetes cluster, you’ll need to have a minimum of three nodes joined together in the cluster. With three nodes, HA will be automatically enabled. You can also join nodes as workers, which can host workloads but do not run the Kubernetes control plan or add to the HA of the cluster. To join a node as a worker, you’d add the –worker flag at the end of the join command like so:
microk8s join 192.168.1.135:25000/f8f7c8b64ed411cf54a8307cead84e73/e0a27e14e027 --worker
And that’s it. You now have a two-node Kubernetes development cluster deployed in under five minutes. This is a great way to get started with container development, as you won’t have to go through the arduous steps of deploying a full-blown Kubernetes cluster.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.