Deploy Portainer on Charmed Kubernetes

1. Overview

If you feel intimidated by Kubernetes’ complexity but still need to modernize your business applications with containers, rest assured you’re not the only one. The container orchestration platform solves many problems but also creates new ones, so read on to find out about a new approach that can help you get just the benefits.

What is Charmed Kubernetes?

Charmed Kubernetes is Canonical’s pure upstream Kubernetes for datacenters. It allows tailoring Kubernetes deployments as it supports multiple cloud infrastructures and a large selection of the CNCF landscape toolset. Based on Juju lifecycle automation framework, Charmed Kubernetes removes the complexity of operating Kubernetes.

What is Portainer?

Portainer is an open source container management tool for Kubernetes, Docker, Docker Swarm and Azure ACI. It allows to deploy and manage containers through an intuitive user interface without the need to write code.

Some pre-reqs for this tutorial:

  • Access to a Linux machine via a ssh terminal, preferably Ubuntu on the latest version;
  • You need the snap package management app installed on the machine you are going to use for your deployment;
  • Access to a Cloud Service Provider like AWS, GCP or Azure. We will use Azure as the CSP for this tutorial so make sure you know what can be the equivalent interfaces/commands if you use a different provider.

2. Initial setup

During the initial setup, you will learn how to install the tools required to set up Charmed Kubernetes and deploy the cluster.

Install the required tools

  1. Run the commands below on your terminal:
    1. snap install juju --classic
    2. snap install kubectl --classic
    3. apt -y install nmap -> this is optional and can be used to check the ports that are open on the public IP address of your node(s)

3. Set up Juju with your cloud provider

  1. Add the cloud provider credentials with juju:juju add-credential azure

  2. You will be prompted to give this credential a name. You can use azure for example:

  3. The next prompt is the selection of the region you would like to use for the deployment. I picked eastus:

  4. The next step is to select the Auth Type. You can just go ahead and use [interactive] by simply hitting Enter:

  5. The next step is to type the Azure Subscription ID that you want to use to deploy your Charmed Kubernetes cluster:

  6. A link to finish setting up the credentials will appear, which you’ll need to open in your browser and paste the code to authenticate. A unique code will be generated every time you add the credentials via juju:

  7. If all goes well, the following message will appear on your browser window:


4. Deploying the Charmed Kubernetes cluster

  1. Start the bootstrap of the juju controller you will deploy on your cloud provider: juju bootstrap azure <name> make sure to replace name with one of your preference. In this example I am going to use charmed01. This process can take up to 15 minutes:

  2. Deploy your Charmed Kubernetes cluster:

    1. For a full cluster you can use juju deploy charmed-kubernetes. This will deploy at least 8 machines with 2 redundant master nodes.
    2. An alternative is to deploy a smaller cluster with one master + one worker node and add more nodes afterwards: juju deploy cs:bundle/kubernetes-core-1200
    3. Add at least 2 more nodes with juju add-unit kubernetes-worker -n 2. You can run this right after step #2 above.
  3. You can monitor the progress of the deployment of your cluster with watch -c juju status --color:

  4. This will take at least 20+ minutes. If all goes well you should see on your screen the following status:

You can hit CTRL+C to exit the juju status screen and go back to the prompt on your terminal window.

  1. Make sure you have a folder called .kube in your home folder. If you don’t create is with mkdir -p $HOME/.kube
  2. Copy the config file from your master node in order to manage the cluster with kubectl: juju scp kubernetes-master/0:config ~/.kube/config
  3. Run a quick test to make sure you can access your cluster with kubectl with kubectl get nodes. You should see your worker nodes on your cluster:

5. Deploying OpenEBS

OpenEBS is an amazing storage option for Kubernetes. Please visit their website to learn more about this project.

  1. Start by enabling the iscsid service on all of your nodes with juju ssh kubernetes-master/0 'sudo systemctl enable --now iscsid'.

  2. Repeat this command for every worker node by replacing kubernetes-master/0 with kubernetes-worker/0 for example: juju ssh kubernetes-worker/0 'sudo systemctl enable --now iscsid'

  3. Enable running privileged services on your master node: juju config kubernetes-master allow-privileged=true

  4. Download the yaml file needed to deploy OpenEBS on your cluster: wget https://openebs.github.io/charts/openebs-operator.yaml

  5. Even though we enable running privileged services on our master node we still need to make a small change to the privileged string on the file:
    sed -i 's/privileged: true/privileged: false/g' openebs-operator.yaml && cat openebs-operator.yaml

  6. Deploy OpenEBS with kubectl: kubectl apply -f openebs-operator.yaml

  7. You can check the status of the OpenEBS deployment with kubectl get pod -n openebs

  8. The deployment will finish once all the containers are running successfully on your cluster:

  9. Finally we need to ensure that the openebs-jiva-default storageclass is set as default by running: kubectl patch storageclass openebs-jiva-default -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

  10. Run kubectl get sc to make sure the patch worked:

This is required otherwise Portainer cannot be installed.


6. Deploying Portainer

  1. Installing Portainer is very easy. All you need is to run kubectl apply -n portainer -f https://raw.githubusercontent.com/portainer/k8s/master/deploy/manifests/portainer/portainer.yaml to install Portainer using NodePort

  2. You can check the status of the installation with kubectl get pod -n portainer. As soon as you see that the STATUS is Running then Portainer is ready to be used:

  3. Portainer, when deployed on a NodePort will run on port 30777. We need to open this port on Azure (or on the CSP you deployed your cluster) to make sure it is accessible on the public IP of your node. You can do this by going to the All Resources page on your Azure portal and selecting the juju-internal-nsg in the juju-default-xxxxxxxx Resource group:

  4. Click on Inbound security rules:

  5. Create a rule that will open port 30777 like this:

  6. You should be able to access Portainer by opening your browser with the public IP address of any of your nodes + port 30777. In my case the public IP of my master node was 20.83.8.178 therefore the link to open Portainer was http://20.83.8.178:30777:

On this page you need to setup the administrator user for Portainer.

  1. The next step is to connect your Portainer instance to you Kubernetes cluster:

  2. The final step is to configure the Kubernetes features of your cluster on Portainer by enabling the metrics server features:

  3. and by enabling the openebs-jiva-default storage class with a RWO, RWX and Volume Expansion:

  4. Click on Save configuration and your Charmed Kubernetes cluster is ready to be managed with Portainer!!


7. That’s all, folks!

You can also follow the demo along on youtube: