Skip to content
Industrial IoT and Edge

Portainer is your solution to securely deploy software containers across your fleet of Edge devices.

blog-banner
Neil Cresswell, CEOFebruary 16, 20215 min read

Proxy and Load Balance your MicroK8s services using Ingress and MetalLB with Portainer

 

Let's learn how to use two very cool MicroK8s networking addons with Portainer; Ingress and MetalLB and even how to combine them with applications deployed on Kubernetes.

I suggest you watch the How-to: Deploy Portainer on MicroK8s video first so you have the right setup for this guide.

MicroK8s addons setup

  1. Let's start by running microk8s status --wait-ready to see which addons are enable:



  2. We need to enable ingress and metallb by typing microk8s enable ingress && microk8s enable metallb
  3. You will notice that you need to provide an IP address range that will be managed by the load balancing feature of metallb.
    1. You can setup a static route on your router that will point to the IP address of the node/cluster where Metallb is being deployed. There are several other ways of doing this and by running a search on your preferred search engine with the string creating static route linux will provide you with several examples. In my case I set a static route on my gateway like this:


      The IP address of my main node is 10.51.1.165
    2. For metallb I defined the IP address range of 10.51.2.10 to 10.51.2.50:

Portainer setup

You can now switch to Portainer to continue the setup.

  1. Login to Portainer and select the endpoint where the MicroK8s were enabled:


  2. On the left hand side menu select Cluster -> Setup:


  3. On the Networking features of your node/cluster you have to:
    1. Enable Allow users to use external load balancer
    2. Configure the Ingress controller with the Ingress class name of public and type nginx:


      It is important that you use public as the ingress class name otherwise the addon will not work.
    3. Finally you need to Enable features using metrics server option and also enable the Storage with RWO, RWX access policy so more than one pods can access your storage concurrently:

That's it for the Portainer setup. Now let's deploy two applications with access via metallb with load balancing and ingress with hostname mapping.

Load Balancer setup example

A good example of when to use the Load Balancer is when an application has to be accessed via a given port like for instance a database engine. So let's deploy a MySQL database:

  1. Select Applications on the let hand side menu and then Add application:


    1. Configure your application by giving it a Name;
    2. Provide the image name on the Image box, in this case mysql:5.6;
    3. It is always good to bundle the deployment under a Stack that I called mysql:


    4. On the Environment variables for mysql you need to add MYSQL_ROOT_PASSWORD that in this example I used db1234:


    5. On the Persistent folders option you might want to set the path in container to /var/lib/mysql and give the database engine at least 20GB of storage:


    6. On the Publishing the application options you need to select Load balancer;
    7. Click on publish a new port;
    8. Fill the container port option and load balancer port option accordingly. For MySQL the default port is 3306:
    9. Finally click on Deploy Application. You should see a message confirming the application has been successfully deployed:
  2. On the Application list page you can enable a very cool feature of Portainer on the Table settings to Auto refresh so you can monitor the status of your applications:


  3. On the Status column you will see that the deployment has finished successfully when the Replicated staus is at least 1/1:


  4. Click on the name of the application mysql to check the IP address that has been assigned by the Load Balancer:


    In this case it was the first IP address defined when metallb was enabled with MicroK8s

That's it. MySQL has been successfully deployed and published via the MicroK8s metallb addon via the IP address 10.51.2.10 on port 3306.

Ingress controller setup example

Now we will combine the ingress addon with the previous MySQL database application by deplying a very popular frontend called phpMyAdmin.

  1. Start by adding a Resource pool and then Add resource pool:


    1. Give the resource pool a name that you can easily identify for the application that you will deploy, in this case phpmyadmin:


    2. On the Ingressess configuration make sure that Allow users to use this ingress is enabled;
    3. You provide a discoverable Hostname that is configured on your DNS server pointing to the main node IP address...
    4. ... and you enable Redirect published routes to / in the application:


    5. Next click on Create resouce pool
  2. You can now add the phpMyAdmin application just like steps #1 through #3 of the Load Balancer setup example above but make sure to select the phpmyadmin on the Resource pool option in this case:


    You can use the same stack name defined previously for the MySQL database if you want
  3. On the Environment variables you will add the IP address of the MySQL database provided by metallb earlier of 10.51.2.10 using the PMA_HOST variable for phpMyAdmin:


  4. You can add a Persistent folder with 10GB, this should be more than enough for phpMyAdmin;
  5. On the Publishing the application configuration you now see the Ingress option available that you will select;
  6. Click on publish a new port that is slighlty different than what we saw on our previous example for the MySQL database and configure the container port to 80, the ingress is already defined with public and the route needs to be /:


  7. Click on Deploy application and monitor the deployment of the application like in the previous example:


  8. Open the application name by clicking on phpmyadmin and you will see the HTTP route that was defined on the Resouce pool for phpMyAdmin:


  9. Click on route and you should be able to access the phpMyAdmin UI:


  10. Let's test if our access to the MySQL database works by typing the Username: root and Password db1234 that we defined on our previous example. If all goes well you should see the default phpMyAdmin page:


In this tutorial we saw the power of combining Portainer with MicroK8s together with the amazing addons that we enabled and managed without having to write complex YAML files.

Hope that worked well for you, and you're up and running with Portainer. If you have any questions or comments, please drop them into the comments section below, or join us on our Slack channel.

You can watch the YouYube video of this here:


Request a Demo of Portainer Business

Let us introduce you to a world of fast and easy app deployment, governance, and management in Docker, Kubernetes, and more. Request a 1:1 demo to see how Portainer Business helps to make teams more accurate and efficient in a business environment.

avatar

Neil Cresswell, CEO

Neil brings more than twenty years’ experience in advanced technology including virtualization, storage and containerization.

COMMENTS

Related articles