MicroK8s and Portainer Is The Easiest Way to Deploy an Application on Kubernetes

Anyone who’s attempted to work with Kubernetes for the first time understands how complicated it is. Not only is creating a Kubernetes cluster a challenge but so too is deploying applications. With so many moving parts, this technology can get the best of anyone who doesn’t have a deep understanding of how it works.
There are, however, shortcuts to take. One such shortcut is deploying Portainer to a MicroK8s cluster. I’ve already demonstrated how this is one in an earlier tutorial. Why would you go this route? Simple. Not only is MicroK8s one of the easiest methods of deploying Kubernetes, but Portainer also offers one of the most powerful and user-friendly GUI tools for managing Kubernetes deployments.
With the Portainer/MicroK8s combination, you have easy access to working with:
- Custom templates
- Namespaces
- Helm
- Applications
- Ingresses
- ConfigMaps & Secrets
- Volumes
- Clusters
- Users
- Environments
- Registries
- Authentication logs
- Notifications
Why wouldn’t you want to use this method for deploying your applications to a Kubernetes cluster? For anyone just getting into the world of Kubernetes, you most certainly would want to take this path of least resistance. In a matter of minutes, you can have a Kubernetes cluster up and running and ready for deployment.
So, with your Portainer/MicroK8s combination up and running, let’s see just how easy it is to deploy your first container to the Kubernetes cluster.
Requirements
The only things you’ll need for this are a MicroK8s cluster of at least three nodes and Portainer up and running. Again, this process is outlined in the link above, so make sure you take care of that before continuing.
Deploying Your First Application
Open a web browser and point it to http://SERVER:30777 or https://SERVER:30779 (where SERVER is either the IP address or domain of the controller node in your cluster).
Once you’ve logged in, select the Local environment and then click Applications. In the resulting window (Figure 1), you’ll see a list of any applications currently running (which will probably only be one, nginx-ingress-microk8s-controller). Click Add With Form near the upper right corner.
-
Figure 1: The Portainer Kubernetes Application window lists all deployed applications.
The form route is the easiest for those who aren’t familiar with creating a Kubernetes manifest. Once you’ve learned more about Kubernetes deployments, you can go the manifest route. Until then, however, stick with the form option.
In the resulting window (Figure 2), you’ll start crafting your application.
-
Figure 2: The Portainer Kubernetes form for deploying an application.
I’ll demonstrate by deploying a simple NGINX application (because who doesn’t love a simple NGINX container). Select the default namespace and then give the application a name, such as nginx-test.
In the Image field, type nginx:latest and make sure docker.io is selected. Next, scroll down and configure the Memory and CPU limits to meet your needs. If you know the application will need to scale, you’ll want to up both units. Just make sure you configure these wisely. Don’t give too much of your system resources over to a single application.
Next, change the instance count for replication. If you want the NGINX container to be replicated to two nodes, type 2 in Instance Count. If you want it to replicate to three nodes, type 3.
Under Publishing The Application, select NodePort and then click Create Service. You will then be asked to fill out the Container Port, Service Port, and NodePort (Figure 3). It is the NodePort that exposes a service externally to the cluster. Without setting the NodePort, you won’t be able to access your application from outside of the container. One thing to note about the NodePort is that it must be within the 30000-32767 range. You can leave it blank and the system will allocate a port for you.
-
Figure 3: Configuring the NodePort for the new application.
Once you’ve configured the NodePort, scroll to the bottom of the window and click Deploy Application. Portainer will set about deploying your container. You’ll then see your applications listed, with the new application in a state of deployment (Figure 4).
-
Figure 4: Our test application is deploying now.
Once the red dot turns green, the application has successfully deployed. Depending on how many nodes you published to, this can take some time. You can click on the container entry to get more information on the status (Figure 5).
-
Figure 5: Our NGINX test is running and has successfully replicated to two nodes.
One really cool thing about this setup is that you can go back to the application details, click the YAML tab, and see what the manifest for the application looks like (Figure 6). This is a good way to learn how Kubernetes manifests are written.
-
Figure 6: The manifest for our nginx-test application.
You can even copy that manifest to your clipboard, paste it into an editor and continue your Kubernetes education outside of Portainer.
And that’s how easy it is to deploy your first Kubernetes application with MicroK8s and Portainer. It doesn’t get any easier than this.