Developing programmer Development Website design and coding technologies working in software company office
Image: joyfotoliakid/Adobe Stock

If you’re a Kubernetes developer, you know how frustrating it can be to have to spin up a full-blown K8s cluster just to work. Your job of developing for Kubernetes is already challenging enough, so having to also take the time to roll out a multi-node cluster can throw a wrench into the works of your day. To add a web-based GUI into the mix is even more of a challenge.

SEE: Hiring kit: Back-end Developer (TechRepublic Premium)

However, thanks to Canonical’s Microk8s, a functioning Kubernetes cluster doesn’t have to be a challenge to create and with the help of the Portainer web-based GUI, which is my go-to container management tool, everything is considerably easier.

Let me show you just how easy it is.

What you’ll need to deploy Portainer

I’ll be demonstrating with Ubuntu Server 22.04, so you’ll need at least three instances of that server and a user with sudo privileges. That’s it.

How to install Microk8s

The first thing we’ll do is install Microk8s on all nodes. To do this, log in to each node and issue the command:

sudo snap install microk8s --classic

Make sure to run the above command on all nodes.

Next, you must add your user to the microk8s group on all nodes with the command:

sudo usermod -aG microk8s $USER

Create a .kube directory with the command:

mkdir ~/.kube

Give that directory the proper permissions with the command:

sudo chown -f -R $USER ~/.kube

How to configure the nodes

Before we go any further, we need to configure our nodes. First, we’ll set the hostnames on each. First, the controller. Well name this machine k8scontroller with the command:

sudo hostnamectl set-hostname k8scontroller

Log out and log back in.

Do the same on each node, only naming them k8snode1, k8snode2, k8snode3 and so on.

Next, we must map the IP addresses in the hosts file. Open that file for editing with the command:

sudo nano /etc/hosts

At the bottom of the file, add something like this (editing to match your IP address scheme):

192.168.1.40 k8scontroller
192.168.1.41 k8snode1
192.168.1.42 k8snode2

Save and close the file.

How to add nodes to the cluster

Next, we’ll add our nodes to the cluster for high availability. To do that, issue the following command on the controller:

microk8s add-node

The above command will output the join command, which will look something like this:

microk8s join 192.168.1.42:25000/4379f43596bc11a0b79171f30053ae01/c8453f5b270d

How to deploy Portainer

Before we deploy Portainer, we must first enable a few extra pieces, which can be done with the command (run on the controller only):

microk8s enable dns ha-cluster ingress metrics-server rbac storage

Once the above command completes, you can then add Portainer into the mix with the command:

microk8s enable portainer

You’ll need to give the container a bit of time to deploy. Once it does, you can access Portainer at http://SERVER:30777, where SERVER is the IP address of the K8s controller. You should be greeted by the Portainer login screen where you can create an initial admin user and you’re all set and can connect Portainer to your local Kubernetes environment.

Congratulations, you just deployed Portainer to a K8s cluster in a couple of minutes. Enjoy that added GUI convenience.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.