Hussle Free Deployment of CloudNative Apps using Napptive
Lets me tell you something very interesting, you gonna learn everything about deploying cloud-native apps in so simple words that you would be WOW !!!! Eureka Moment and let me remind you of everything in practical
So I hope you are as much excited as I am.
So lets Start
We are living in a world of very less downtime, people have go so addicted to screens and no one wants to see that the apps they are using is crashing or is down for a very long time and in case even if you want to build an app like that then it's very important for you to understand about cloud-native apps, these are those apps with almost 0 downtimes and scale to large users with ease.
But the important question is how? let's understand that and deploy an cloud-native app
We have created a simple application so that you guys can get a hands-on experience.
Source Code of the app - GitHub link which contains the source code of the app here which we are going to deploy.
so let's understand the app first
This is a monolithic project management app built using MERN Stack which has the components shown in the figure below
So it's ok if you don't understand the coding of the app, that's not the focus of this blog, the only focus of this blog is how you can deploy any given app using captive making it hassle-free and easier for developers.
So let's say we have our app ready now and you can run it locally using npm start.
Now comes an important part of how the deployment of this app is going to happen.
For that, we need to first understand how cloud-native are deployed and once that makes sense we will how we can do the same thing in a very simple way using captive
So first we need to create a docker image of your app and you can do that using a docker file which contains all the details about how the docker container is going to be created.
since you have a docker file you can create a docker image using the docker file and build a container inside which your app runs. Very simple right
The Docker file example for our project is shown below
FROM node:16-buster
# What is Dockerfile?
# Dockerfile describes how to build Docker images,
# while docker-compose is used to run Docker containers.
# Create an application directory
RUN mkdir -p /usr/src/app
# CD into directory
WORKDIR /usr/src/app
# Copy the app package and package-lock.json file
# COPY package.json /app/package.json
# COPY package-lock.json /app/package-lock.json
COPY package*.json /usr/src/app/
# Install app dependencies
RUN npm install
# RUN mkdir node_modules/.cache && chmod -R 777 node_modules/.cache
# Bundle app source
COPY . /usr/src/app/
EXPOSE 3000
CMD [ "npm", "start" ]
But the problem comes when we have many such containers and it's becoming very difficult to manage your containers.
Some problems are faced when you have multiple containers running
Figuring out which containers are running and which are not running
Restarting containers which are stopped
Managing these huge sets of containers is very difficult
This issue is solved by Kubernetes (K8s)
Kubernetes comes with lots of amazing features like auto-healing, and auto-scaling which means it can automatically restart stopped containers, it can give birth to new containers when the load on the app is increasing and you are getting heavy traffic. Sound amazing right?
So let's see how we can do this using Kubernetes. Now let's deploy our app using Kubernetes
Kubernetes is an amazing tool but it is not so easy to use and we need to create lots of configuration files like deployment files, services files for each container which is very tedious to do.
Here is an example of Kubernetes configuration files which help in the deployment of our app.
Backend Deployment File for backend container
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
labels:
io.kompose.service: backend
name: backend
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: backend
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
labels:
io.kompose.service: backend
spec:
containers:
- env:
- name: MONGO_URI
value: mongodb://mongo:27017
image: omaximani/pm-be
name: server
ports:
- containerPort: 5000
resources: {}
volumeMounts:
- mountPath: /usr/src/app
name: backend-claim0
- mountPath: /usr/src/app/node_modules
name: backend-claim1
restartPolicy: Always
volumes:
- name: backend-claim0
persistentVolumeClaim:
claimName: backend-claim0
- name: backend-claim1
persistentVolumeClaim:
claimName: backend-claim1
status: {}
Backend service File for backend container
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
labels:
io.kompose.service: backend
name: backend
spec:
ports:
- name: "5000"
port: 5000
targetPort: 5000
selector:
io.kompose.service: backend
status:
loadBalancer: {}
So this is not all it. For the app that we have build there are lot of still files that we need to make our app ready to use.
All the files are mentioned in the GitHub Repository
So lots of configurations files right no easy for a company with a very small team to manage all this
So the next question is what's the solution
Napptive is a Kubernetes deployment platform which makes is so easy to deploy scale apps and lets developers focus on coding and not spending more time in the deployment process and all the configurations
So now let's do the same thing we did use k8s using captive.
lets understand the structure of the YAML file using for configurations first
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
# Name of the application which will be used to refer to it once deployed.
name: <name>
spec:
# List of components that are part of the application.
components:
# Each component must have a name. The name will be used during the translation process
# to Kubernetes entities.
- name: <component name>
# Each component is associated with a type. The type works as a template and defines
# how a high-level component will be translated into Kubernetes.
type: <component type>
# Properties that can be configured for the user. This can be use to set the parameters
# that are defined by the component type.
properties:
<parameter values>
# Traits are extensions that augment the capabilities of a component. For example,
# changing the replication, importing a config map, etc.
traits:
- type: <trait type>
properties:
<traits parameter values>
These are the steps you have to follow to do that
Install the napptive CLI
Once the Napptive CLI is installed, you can use it to create a new Napptive project. This project will serve as a container for your OAM application
Add the Napptive OAM plugin: Napptive provides an OAM plugin that you can add to your Napptive project to enable OAM functionality. You can add this plugin by running the following command in your project directory
napptive plugin add oam
Define the OAM components: You will need to define your OAM components in your Napptive project. This includes creating a component.yaml file for each component in your OAM application. The component. yaml file describes the properties of the component, including its name, type, and configuration.
Build and deploy your OAM application: Once you have defined your OAM components in your Napptive project, you can use the Napptive CLI to build and deploy your application to the Napptive platform. You can do this by running the following command
napptive deploy
Test and manage your OAM application: After your OAM application is deployed to the Napptive platform, you can test and manage it using the Napptive CLI or the Napptive web console. You can monitor your application's health, view logs, and make updates to your application's configuration.
And that's it things are made very simple using captive
Hope you loved reading this blog.
This is the github link which contains project source code and all deployment ks8 files
Special Thanks to Mohammad Arif , the code used in this guide is forked from the work done by Mohammad Arif.
Subscribe to my newsletter
Read articles from Gautam Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by