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.
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.
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
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
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.
You can check all the resources created in the cluster using the following commands
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
You can check the created deployments like this
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
You can check all the created deployments like this
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
That’s it! Now, you’ll be able to use the frontend app. Here is how the app looks like
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.
Like this post? Don’t forget to share it!
62% of UX designers now use AI to enhance their workflows. Artificial intelligence (AI) rapidly…
The integration of artificial intelligence into graphic design through tools like Adobe Photoshop can save…
The cryptocurrency trading world has grown significantly in recent years, with automation playing a key…
The non-fungible token (NFT) market has witnessed explosive growth over the past few years, transforming…
There are few things as valuable to a business as well-designed software. Organizations today rely…
The cryptocurrency industry is being reshaped by the fusion of blockchain technology and artificial intelligence…
This website uses cookies.