A developer writes code on multiple screens.
Image: Gorodenkoff/Adobe Stock

Blink and technology changes. It was only several months ago that I wrote a TechRepublic tutorial on deploying Portainer to a Microk8s cluster for simplified Kubernetes development. Now that tutorial no longer works, because the latest versions of Microk8s have trouble clustering, and the versions of Microk8s prior to 1.24 won’t work with Portainer. Read on to learn the new process of deploying this all-in-one container management platform to a Microk8s cluster.

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

What you need to deploy Portainer to Microk8s

You’ll need a Microk8s cluster with at least three nodes and a user with sudo privileges.

How to install Microk8s and join the cluster

Here’s a quick refresher on how to deploy a Microk8s cluster properly.

  1. Install version 1.24 of Microk8s on all Ubuntu Server nodes via snap.
  2. Edit your /etc/hosts file to map hostnames to IP addresses.
  3. Set the hostnames for each machine.
  4. Set the proper timezone on all machines.
  5. Run the microk8s add-node command on the controller.
  6. Run the microk8s join command, shown in the output of the add-node command, on every node.
  7. Add your user to the microk8s group with sudo usermod -aG microk8s $USER.
  8. Change the permission of the .kube folder with chown -f -R $USER ~/.kube.
  9. Log out and log back in.

Now that you have your cluster up and running, it’s time to deploy Portainer to the cluster.

How to deploy Portainer to a Microk8s cluster

First, enable a few add-ons to Microk8s. Log in to your Microk8s controller and issue the following commands to enable the necessary add-ons:

microk8s enable dns

microk8s enable ha-cluster

microk8s enable ingress

microk8s enable metrics-server

microk8s enable rbac

microk8s enable hostpath-storage

Before enabling Portainer, you must enable the community repository with the command:

microk8s enable community

Now, you can enable Portainer with:

microk8s enable portainer

Give Portainer enough time to spin up – you can check the status with the following command:

microk8s kubectl get pods -n portainer

When you see Portainer listed as running, you can open a web browser and point it to http://SERVER:30777 or https://SERVER:30799, where SERVER is the IP address or domain of the hosting server.

You will be prompted to create an admin user. After you take care of that, select the local environment, and you’ll find yourself on the Portainer Dashboard (Figure A), where you can start managing your Kubernetes deployments.

Figure A

The Portainer Dashboard as seen on a Microk8s cluster.
The Portainer Dashboard as seen on a Microk8s cluster.

Watch for the latest releases of Microk8s

Now you know how to properly deploy Portainer to a Microk8s cluster; however, since this could change, you should watch for the latest releases of Microk8s on the Snap store. As soon as the latest stable version of Microk8s is better capable of clustering, I highly recommend you upgrade to that release and re-deploy Portainer.

Check these resources from TechRepublic Academy to learn more about Developing on Kubernetes :
The Docker and Kubernetes Certification Training Bundle 
The Ultimate Kubernetes & Cloud Certification Training Bundle
The 2022 DevOps Cloud Engineering Prep Bundle 

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays