Modal Title
Cloud Native Ecosystem / Kubernetes

Set Up MicroK8s to Run an Edge Application

MicroK8s lets you cluster Kubernetes installations together so they can form a single cluster and place workloads on one or more of these nodes. In this article, we will learn how to deploy onto a MicroK8s cluster an application based on Stateful Angular, Spring Boot, and Postgres, in which users can create a customer with attributes 'Name' and 'Age.'
Sep 9th, 2020 6:00am by
Featued image for: Set Up MicroK8s to Run an Edge Application
Feature image via Pixabay.

We already know that Kubernetes is the world’s preferred orchestration platform for container-based applications, automating the deployment and scaling of these apps, and streamlining maintenance operations. However, Kubernetes comes with its own complexity challenges. So how can an enterprise take advantage of containerization to tackle Internet of Things complexity and not end up with yet more complexities of Kubernetes?

Canonical’s MicroK8s is a powerful, Cloud Native Computing Foundation-certified Kubernetes distribution. Here are some of the key reasons, I feel, why it has become a powerful enterprise edge computing platform:

  • Delivered as snap packages: These are app packages for desktop, cloud, and IoT that are easy to install and secure with auto-updates and can be installed on any of the Linux distributions that support snaps. This makes MicroK8s ideal for running on the vast variety of hardware that comprises the IoT.
  • Strict confinement: This ensures complete isolation from the underlying operating system and a tightly secured production-grade Kubernetes environment, all in a small footprint ideal for edge gateways.
  • Production-grade add-ons: Istio, KnativeCoreDNSPrometheusJaegerLinkerdCilium, and Helm are available as add-ons these are simple to set up, with just a few lines of commands.
  • Kubeflow is also available as an add-on to MicroK8s for improved artificial intelligence (AI) and machine learning (ML) capabilities.

With its ability to reduce complexity, MicroK8s is going to accelerate IoT and edge deployments. Treating IoT devices like distributed containerized applications allows developers to focus on applications rather than infrastructure and make life easier for operations teams.

MicroK8s lets you cluster Kubernetes installations together so they can form a single cluster and place workloads on one or more of these nodes. In this article, we will learn how to deploy onto a MicroK8s cluster an application based on Stateful Angular, Spring Boot, and Postgres, in which users can create a customer with attributes “Name” and “Age.”

If you’re new to Kubernetes, I recommend reading the following hands-on guides before reading this one

Set up a MicroK8s Cluster

Image – Sample Application.

To deploy this application, we would be using PersistentVolume (PV) which is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned. PVs are volume plugins like Volumes but have a lifecycle independent of any individual pod that uses the PV.

PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., they can be mounted ReadWriteOnce, ReadOnlyMany or ReadWriteMany).

In the next section, we will look how to install and deploy our application on to MicroK8s cluster.MicroK8s is deployed via Snaps. Snaps are containerized (like Docker) software packages that are easy to create and install, they bundle their dependencies, they work on all major Linux systems without modification. Snaps auto-update and are safe to run. Also, note MicroK8s snap would be frequently updated to match each release of Kubernetes.

MicroK8s snap can be installed using the command below:

snap install microk8s --classic --beta

If you’re looking for detailed steps, please refer to this article.

At this point, we have installed MicroK8s, check whether the newly deployed node is in Ready state using the following command.

kubectl get nodes

Image – 2-node Microk8s Cluster

 

Deploy Postgres on Kubernetes using PersistentVolume


We have created four resources in the above manifest file. A PersistentVolume, a PersistentVolumeClaim for requesting access to the PersistentVolume resource, a service for having a static endpoint for the Postgres database, and a deployment for running and managing the Postgres pod.

The Postgres container reads database credentials from environment variables using postgres-config ConfigMap.


Let’s now deploy Postgres by applying the YAML configuration:

Image – Apply Postgres Deployment.

You can check all the resources created in the cluster using the following commands:

Image – Status of Postgres deployment.

Image – Postgres PV,PVC Deployments.

Deploy the Spring Boot app on Kubernetes

Now that we have the Postgres instance deployed, Let’s proceed with the deployment of the Spring Boot app.

The following is the deployment manifest for the Spring Boot app:


The above deployment uses the ConfigMaps stored in postgres-config that we created in the previous section.

Let’s apply the manifest file to create the resources

Image – Create SpringBoot Deployment.

You can check the created deployments like this:

Image – Status of the deployments.

Deploy the Angular App on Kubernetes

Next step is to deploy the Angular app using Kubernetes, here is the deployment manifest:


Let’s apply the above manifest file to deploy the Angular app

Image – Create Angular Deployment

You can check all the created deployments like below:

Deploy Ingress

Final step is to deploy Ingress that provides external access to the services in a cluster.


Let’s apply the above manifest file to deploy the Ingress service:

Image – Deploy Ingress service

You can check all the created ingress deployment like below:

Image – Ingress is created

You can check all the Services created using the command below:

Image – Services List

That’s it! Now, you’ll be able to use the frontend app. Here is how the app looks like:

Image – Create Customer

Image – Customer has been created

MicroK8s gives you troubleshooting tools to check out what has gone wrong. Be sure to check out the common issues section for help in resolving the frequently encountered problems.

With its ability to strengthen Kubernetes productivity, and reduce complexity MicroK8s is a uniquely positioned for accelerating IoT and edge deployments.

Useful Resources :

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Docker.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.