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
- Let's start by running
microk8s status --wait-ready
to see which addons are enable: - We need to enable ingress and metallb by typing
microk8s enable ingress && microk8s enable metallb
- You will notice that you need to provide an IP address range that will be managed by the load balancing feature of metallb.
- 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 - For metallb I defined the IP address range of 10.51.2.10 to 10.51.2.50:
- 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:
Portainer setup
You can now switch to Portainer to continue the setup.
- Login to Portainer and select the endpoint where the MicroK8s were enabled:
- On the left hand side menu select Cluster -> Setup:
- On the Networking features of your node/cluster you have to:
- Enable Allow users to use external load balancer
- 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. - 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:
- Select Applications on the let hand side menu and then Add application:
- Configure your application by giving it a Name;
- Provide the image name on the Image box, in this case mysql:5.6;
- It is always good to bundle the deployment under a Stack that I called mysql:
- On the Environment variables for mysql you need to add MYSQL_ROOT_PASSWORD that in this example I used db1234:
- 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:
- On the Publishing the application options you need to select Load balancer;
- Click on publish a new port;
- Fill the container port option and load balancer port option accordingly. For MySQL the default port is 3306:
- Finally click on Deploy Application. You should see a message confirming the application has been successfully deployed:
- 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:
- On the Status column you will see that the deployment has finished successfully when the Replicated staus is at least 1/1:
- 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.
- Start by adding a Resource pool and then Add resource pool:
- Give the resource pool a name that you can easily identify for the application that you will deploy, in this case phpmyadmin:
- On the Ingressess configuration make sure that Allow users to use this ingress is enabled;
- You provide a discoverable Hostname that is configured on your DNS server pointing to the main node IP address...
- ... and you enable Redirect published routes to / in the application:
- Next click on Create resouce pool
- Give the resource pool a name that you can easily identify for the application that you will deploy, in this case phpmyadmin:
- 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 - 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:
- You can add a Persistent folder with 10GB, this should be more than enough for phpMyAdmin;
- On the Publishing the application configuration you now see the Ingress option available that you will select;
- 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 /:
- Click on Deploy application and monitor the deployment of the application like in the previous example:
- Open the application name by clicking on phpmyadmin and you will see the HTTP route that was defined on the Resouce pool for phpMyAdmin:
- Click on route and you should be able to access the phpMyAdmin UI:
- 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.
COMMENTS