Kubernetes Guides

Set Up MicroK8s to Run an Edge Application

We already know that Kubernetes is the No. 1 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 IoT complexity and not end up with yet more complexities of Kubernetes?

MicroK8s is a powerful, Cloud Native Computing Foundation-certified Kubernetes distribution, here are some of the key reasons 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, Knative, CoreDNS, Prometheus, Jaeger, Linkerd, Cilium, 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 Stateful Angular + Spring Boot +Postgres Application on to MicroK8s cluster.

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

The sample application is a Fullstack Angular, SpringBoot, Postgres app where users can create a customer with attributes Name and Age.

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)

Cross Posted from TheNewStack

Step#1. Setup 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

Step#2.Deploying Postgres on Kubernetes using PersistentVolume

Following is the Kubernetes manifest for Postgres deployment.

kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv-volume
labels:
type: local
app: postgres
spec:
storageClassName: manual
capacity:
storage: 100Mi
accessModes:
- ReadWriteMany
hostPath:
path: "/var/lib/postgres"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pv-claim
labels:
app: postgres
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Mi
---

apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres

replicas: 1
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:10.4
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
envFrom:
- configMapRef:
name: postgres-config
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgredb
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: postgres-pv-claim

---

apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
type: NodePort
ports:
- port: 5432
selector:
app: postgres

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.

apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
labels:
app: postgres
data:
POSTGRES_DB: postgresdb
POSTGRES_USER: postgresadmin
POSTGRES_PASSWORD: admin123

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

Step#3.Deploying 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.

Following is the deployment manifest for the Spring Boot app

apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot
namespace: default
spec:
selector:
matchLabels:
app: spring-boot

replicas: 1
template:
metadata:
name: spring-boot
labels:
app: spring-boot
spec:
containers:
- name: spring-boot
env:
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: postgres-config
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
configMapKeyRef:
name: postgres-config
key: POSTGRES_PASSWORD
- name: POSTGRES_HOST
valueFrom:
configMapKeyRef:
name: hostname-config
key: postgres_host
image: karthi4india/orderapi:latest

---

apiVersion: v1
kind: Service
metadata:
name: spring-boot
labels:
app: spring-boot
spec:
type: NodePort
ports:
- port: 8080
selector:
app: spring-boot

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

Step#4.Deploying the Angular app on Kubernetes

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

apiVersion: apps/v1
kind: Deployment
metadata:
name: angular
namespace: default
spec:
selector:
matchLabels:
app: angular
replicas: 1
template:
metadata:
name: angular
labels:
app: angular
spec:
containers:
- name: angular
image: 'karthi4india/orderui:latest'
imagePullPolicy: Always
volumeMounts:
- name: env-vars
mountPath: /usr/local/apache2/htdocs/assets
volumes:
- name: env-vars
configMap:
name: angular-env-vars

---
apiVersion: v1
kind: Service
metadata:
name: angular
labels:
app: angular
spec:
type: NodePort
ports:
- port: 4200
selector:
app: angular

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

Image – Create Angular Deployment

You can check all the created deployments like this

Image – Status of all the deployments
Image – Services List

Step#5.Deploy Ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1

# UPDATE THIS LINE ABOVE
spec:
rules:
- http:
paths:
- path: /?(.*)
# UPDATE THIS LINE ABOVE
backend:
serviceName: angular
servicePort: 4200
- path: /api/?(.*)
# UPDATE THIS LINE ABOVE
backend:
serviceName: spring-boot
servicePort: 8080

Image – Deploy Ingress service
Image – Ingress is created

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 uniquely positioned for accelerating IoT and edge deployments.

Useful Resources :

Like this post? Don’t forget to share it!

Summary
Article Name
Set Up MicroK8s to Run an Edge Application
Description
With its ability to strengthen Kubernetes productivity, and reduce complexity MicroK8s is a uniquely positioned for accelerating IoT and edge deployments.
Author
Publisher Name
Upnxtblog
Publisher Logo
Karthik

Allo! My name is Karthik,experienced IT professional.Upnxtblog covers key technology trends that impacts technology industry.This includes Cloud computing,Blockchain,Machine learning & AI,Best mobile apps, Best tools/open source libs etc.,I hope you would love it and you can be sure that each post is fantastic and will be worth your time.

Share
Published by
Karthik

Recent Posts

Finding the Right Time to Build Your Software Instead of Buy

There are few things as valuable to a business as well-designed software. Organizations today rely…

2 days ago

Innovators in Crypto: Prominent AI-Powered Coins

The cryptocurrency industry is being reshaped by the fusion of blockchain technology and artificial intelligence…

3 weeks ago

Top AI Design Tools Every Graphic Designer Should Use in 2024

Introduction Artificial Intelligence (AI) has also found its relevance in graphic design and is quickly…

2 months ago

Transforming Industries: The Integration of AI and Blockchain

Imagine a world where the brilliance of Artificial Intelligence (AI) meets the unbreakable security of…

2 months ago

How Can I Use Automation to Streamline My Digital Marketing Efforts?

In today’s fast-paced digital landscape, automation is not just a luxury but a necessity for…

2 months ago

Top 5 AI Technologies Transforming the Casino Gaming Landscape in 2025

The world of casino gaming has leveraged the emerging technology advancements to create immersive and…

2 months ago

This website uses cookies.