How to deploy Portainer on a microk8s cluster to simplify your Kubernetes development

Jack Wallen shows you how to deploy the Portainer web-based container manager on a microk8s cluster for more efficient development.

Developer programmer 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 spin up an entire K8 cluster just to get it up and running. Your development work for Kubernetes is already challenging enough that having to take the time to deploy a multi-node cluster can make your day’s work difficult. Adding a web-based GUI to the mix is ​​an even bigger challenge.

SEE: Hiring Kit: Back-End Developer (TechRepublic Premium)

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

Let me show you how easy it is.

What you’ll need to implement Portainer

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

How to install Microk8s

The first thing we will 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 need to 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 continue, we need to configure our nodes. First, we’ll configure the hostnames on each. First, the controller. Well, name this machine k8scontroller with the command:

sudo hostnamectl set-hostname k8scontroller

Sign out and sign in again.

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

Next, we need to assign 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 (edit to match your IP address scheme): k8scontroller k8snode1 k8snode2

Save and close the file.

How to add nodes to the cluster

Next, we will 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 generate the join command, which will look like this:

microk8s join

How to implement Portainer

Before we implement Portainer, we first need to enable a few additional pieces, which can be done with the (run on controller only) command:

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

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

microk8s enable portainer

You’ll need to give the container some time to deploy. Once you do, you can access the 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 are all set to connect Portainer to your local Kubernetes environment.

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

Subscribe to TechRepublic’s How To Make Tech Work on YouTube to get the latest tech tips for business professionals from Jack Wallen.

Leave a Comment