How to deploy Portainer to a MicroK8s environment

If you want to add Kubernetes to your development workflow, try the easy way with a combination of Microk8s and Portainer.

A developer writing code on multiple screens.
Photo: Gorodenkoff/Adobe Stock

flicker and technology changes. Just a few months ago I wrote a tutorial for TechRepublic about deploying Portainer in a Microk8s cluster for simplified Kubernetes development. Now this tutorial no longer works, because the latest Microk8s have a compilation problem, and Microk8s versions prior to 1.24 will not work with Portainer. Read on to learn about the new process for deploying this all-in-one container management system on a Microk8s cluster.

We see: Recruitment group: Back-end developer (TechRepublic Premium)

What you need to deploy Portainer on Microk8s

You will 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 properly deploy a Microk8s array.

  1. Install Microk8s version 1.24 on all Ubuntu server nodes via Snap.
  2. Edit your /etc/hosts file to map hostnames to IP addresses.
  3. Set host names for each device.
  4. Set the appropriate timezone on all devices.
  5. Run microk8s add-node command on the console.
  6. Run microk8s join command, as shown in the output file add-node command, on each node.
  7. Add your user to the microk8s group using sudo usermod -aG microk8s $USER.
  8. Change the .kube folder permission with chown -f -R $USER ~/.kube.
  9. Log out and log back in.

Now that your group is up and running, it’s time to deploy Portainer to the group.

How to deploy Portainer in Microk8s group

First, enable some of the Microk8s add-ons. Log into your Microk8s console 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 the Portainer enough time to spin – 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 administrator user. After that’s taken care of, select Local Environment, and you’ll find yourself in the Portainer Dashboard (Figure A), where you can start managing your Kubernetes deployments.

Figure A

The Portainer Dashboard as seen on the Microk8s kit.
The Portainer Dashboard as seen on the Microk8s kit.

See the latest releases of Microk8s

Now you know how to properly deploy Portainer to a Microk8s pool; However, as this may change, you should keep an eye on the latest Microk8s on the Snap Store. Once the latest stable release of Microk8s is better able to compile, I highly recommend upgrading to this release and redeploying Portainer.