TNS
VOXPOP
Where are you using WebAssembly?
Wasm promises to let developers build once and run anywhere. Are you using it yet?
At work, for production apps
0%
At work, but not for production apps
0%
I don’t use WebAssembly but expect to when the technology matures
0%
I have no plans to use WebAssembly
0%
No plans and I get mad whenever I see the buzzword
0%
Cloud Native Ecosystem / Kubernetes

Add Nodes to Your MicroK8s Kubernetes Cluster

How to join nodes to a controller to create your first Kubernetes cluster by way of Microk8s.
Dec 10th, 2022 4:00am by
Featued image for: Add Nodes to Your MicroK8s Kubernetes Cluster
Feature image by jarmoluk via Pixabay.

Kubernetes is hard. There’s no way around that. With so many moving pieces, all of which have to interconnect, and complicated manifests, the technology can be rather daunting. Should you dive in too fast, you might become overwhelmed to the point where you’re not sure which way to go1

That’s why it’s important to approach Kubernetes slowly and with a one-step-at-a-time approach. In this Kubernetes 101 series, we’ve previously covered deploying MicroK8s to a single server, powered by Rocky Linux.

This time around we’re going to add nodes to our first Kubernetes machine to create a cluster. These nodes are all managed by the original machine, which I call the controller. You’ll want to make sure to have followed the “Kubernetes 101: The easiest route to installing Kubernetes on Rocky Linux” tutorial and make sure to do this on all of the nodes you need for the cluster. Once you’ve taken care of those steps on every machine, you’re then ready to start adding nodes to the cluster.

For my cluster, I’ll have three nodes and one controller. The IP address scheme looks like this:

  • 192.168.1.100 kubecontroller
  • 192.168.1.101 kubenode1
  • 192.168.1.102 kubenode2
  • 192.168.1.103 kubenode3

It’s also important to change the hostname for each node. Remember, the command to change a hostname on Linux is:


Where NAME is the hostname you want to give the machine. In our case, those hostnames will be:

  • kubecontroller
  • kubenode1
  • kubenode2
  • kubenode3

Edit the Hosts File on the Nodes

The first thing we’ll do is edit the hosts file on every machine. Open that file with:


At the bottom of the file, we’ll add:


Save and close the file with the [Ctrl]+[X] keyboard shortcut.

Open the Necessary Firewall Ports

In order for the nodes to be able to communicate to the controller, you must open the necessary firewall ports. This is done on the controller with the commands:


On each node, you will also need to open specific firewall ports with the following commands:


You might also need to add one more port (on all machines) with the commands

Generate the Add Node Command

Still, on the controller, you must run a command that will then generate the required add command. That command is:


The output will include the full command to be run on each node to be joined. That command will look something like this:


After you’ve run the join command on all nodes, give it a few minutes to make sure everything is up and running. You can then check the nodes from the controller with the command:


You should see all three nodes are now part of the cluster.

Making This a Bit Easier

As you can see, with MicroK8s, you’re using the kubectl command via the microk8s command. That’s a bit more typing than you might want to deal with. Fortunately, you can set MicroK8s to use the system version of the kubectl command. To do that we first install the kubectl command on Rocky Linux with the following:


Next, we generate a config file and save it in ~/.kube/ with the command:


You should now be able to use the kubectl command without the need to type microk8s. For example, to view the newly-added nodes, the command would now be:


You don’t have to go this route. If you don’t mind the extra typing, microk8s kubectl is a perfectly find way to go.

Removing a Node from the Cluster

On the off-chance you need to remove a node from you cluster, all you have to do is log in to that node, and issue the command:

Adding More Nodes Later

You are not just limited to the nodes you add this round. Once upon a time I used to just save the join command to a file and copy/paste it anytime I needed. That no longer works because the join token is time sensitive. Even so, you can add and remove nodes as needed to increase or decrease the size of your cluster. Any time you need to join a new node, all you have to do is run the join command, like so:


You’ll receive the same join command you ran on the initial nodes, only with a different join token. If you try to rerun the same join command as you did early, you will get an invalid token command. So make sure you remember the add-node command so you can join more nodes later on.

And that’s all there is to joining nodes to a controller to create your first Kubernetes cluster by way of MicroK8s.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Bit.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.