Kubernetes 101: Deploy Your First Application with MicroK8s

Kubernetes is challenging. There is no dispute about that. Deploying containers to a Kubernetes cluster has many moving parts, and many things can go wrong along the way. Further complicating matters is that deploying a Kubernetes cluster can be a brain-wrenching task.

That’s why tools like Canonical’s MicroK8 were developed. With such software, the process of deploying a Kubernetes cluster is much less demanding, allowing you to focus more on accelerating the deployment of applications and services to your cluster.

One of the many things you need to do to deploy applications and services to your Kubernetes cluster is to access it. For example, unlike Docker, when you deploy an application or service to a Kubernetes cluster, it is not automatically available on the network. If you are on a machine that is part of a cluster, you can definitely access that app or service because that machine has access to the subnet used by the cluster. Without a little extra trickery, those applications and services aren’t available outside the cluster. That is, you must manually enable it.

again… Lots of moving parts.

We have already seen the steps to install Microk8 on Rocky Linux and then connect the node to the controller. Add nodes to create clusters on which you can deploy applications and services.

What we’re going to do now is show you how to deploy your first application to a cluster and then make that application accessible from outside the cluster. One thing to note is that deploying applications/services to a MicroK8s cluster is similar to any other Kubernetes deployment. The biggest difference for users is that the deployment requires MicroK8s commands, whereas other Kubernetes distributions do not have that requirement.

Also Read :  Guide to securing data during cloud migration

Things that you need

The only thing needed for this is one or more controllers and a running MicroK8s cluster of 2 nodes. It can be deployed in data centers, test networks, or third-party cloud hosts. All you need is that the node is connected to the controller.

If you are not sure if the nodes are connected, log in to the controller and run the following command:

All nodes connected to the controller should be listed. If not, you will need to take steps to reconnect the nodes.

How to deploy your first application with MicroK8s

Log in to the MicroK8s controller. This demo deploys the NGINX web server application. Name this deployment nginx-webserver and use the official NGINX container image for the deployment. The command for this is:

The output of that command should be:

Use the following command to verify the deployment was successful.

You should see something like the following in the output.

Congratulations. The first pod has been deployed into the cluster. What is a Pod? A Kubernetes pod is a collection of one or more containers and is the smallest unit of an application. A pod usually consists of multiple integrated containers, but can also consist of a single container. In the instance above, we deployed a pod with a single container (NGINX).

At this point, the NGINX application is running but not accessible. You must also deploy the service to make it accessible. What we are going to do here is expose our nginx-webserver deployment on port 80 using the “NodePort” type. What are NodePorts? In simple terms, a NodePort is an open port on every node connected to the cluster. Kubernetes routes incoming traffic from the NodePort to your deployed service or application.

The command to deploy the service is:

Also Read :  Harnessing the power of the world's fastest computer

The output of the command should be:

When I try to access a container running on port 80, such as, I cannot access it. What do you offer? Kubernetes maps internal port 80 to a random internal port. You need to find the mapped port before accessing the running web server. For that, run the following command:

The output should be:

As you can see, Kubernetes has mapped internal port 80 (the port being used by NGINX) to external port 31508 (the port being used by the Kubernetes cluster). So, point your web browser to and your browser should display the NGINX welcome screen.

Of course it uses the IP address of one of the nodes. However, the NGINX site does not appear when using the controller’s IP address. why? This is because the controller deploys the container to a node rather than itself.

All you need to do is deploy your first application to a Kubernetes cluster using MicroK8s.

group Made with sketches.


Leave a Reply

Your email address will not be published.