In this Code Pattern, we will build a cloud native application based on microservice architecture, IBM Middlewares and following 12 factor practices. This application is an Airline Booking app, and the technologies behind this app are:-
- Nodejs (Typescript)
- IBM DB2
- IBM ODM
- RabbitMQ
- MariaDB
- MongoDB
- Here Map
- Celery
- Angular
- Docker
- Kubernetes
- IBM Cloud Private
- Istio
- Calico
Cloud native application is a buzzword these days. Technologies like Kubernetes and Docker are picking up reputation and popularity in Cloud native world. This Pattern will show an end to end process of building highly available Cloud Native Application on IBM Cloud Private. The Application backend is based on Nodejs and DB2, MariaDB, and MongoDB as a Database. The frontend is built using Angular4. Distributed Asynchronous task queue is based on RabbitMQ and Celery. Container orchestration is managed by Kubernetes.
When you've completed this Code Pattern, you will understand how to:
- Break the application into different microservices
- Deploying microservices based application on IBM Cloud Private
- Leveraging IBM Middlewares such as ODM and DB2 on Kubernetes
- Using Istio to build service mesh
- Using Grafana, Prometheus, kiali, and Weavnet for visualisation
- Securing kubernetes networking through Calico
- Designing business rules and decision by IBM ODM
- Create distributed task ques using RabbitMQ and Celery
- Leveraging DB2, MariaDB, and MongoDB as backend data storage
- Learn how to use IBM Cloud Private, Docker, and Kubernetes
- Leveraging Heremap to fetch nearby landmarks
- Mobile App:- End user mobile app who will access the application. It leverages restful endpoints by backend microservices
- Portal:- The user interface is built using Angular4. It leverages restful endpoints by backend microservices
- Authentication Microservice:- This Microservice allows the user to login signup to the application
- Listing Microservice:- This Microservice allows the user to list and browse the available flights
- Booking Microservice:- This Microservice allows the user to checkin to a given booked flight, and book an available flight
- ODM Microservice:- This Microservice helps to communicate with the ODM Service
- Email Microservice:- Email Microservice communicates with RabbitMQ and Celery to send email in asynchronous ques
- Map Microservice:- Map Microservice communicates with Here Map api to fetch nearby landmarks
- IBM DB2:- SQL Database for authentication microservice
- MongoDB:- NOSQL Database for listing microservice
- MariaDB:- NOSQL Database for booking microservice
- ODM:- IBM Operational Decision Manager is an advanced business rules management system that helps you capture, automate and govern frequent, repeatable business decisions and adds real-time decision making to your day-to-day operations
- RabbitMQ:- RabbitMQ is a messaging broker - an intermediary for messaging. It gives your applications a common platform to send and receive messages, and your messages a safe place to live until received.
- Here Map:- Here map api to fetch nearby locations
- Angular:- Angular is a platform that makes it easy to build applications with the web. Angular combines declarative templates, dependency injection, end to end tooling, and integrated best practices to solve development challenges
- Nodejs:- An open-source JavaScript run-time environment for executing server-side JavaScript code.
- Typescript:- TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language
- Docker:- Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
- Kubernetes:- Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications
- IBM DB2:- DB2 is a database product from IBM. It is a Relational Database Management System (RDBMS)
- IBM ODM:- IBM® Operational Decision Manager is a comprehensive decision automation platform that helps you capture, analyze, automate and govern rules-based business decisions
- RabbitMQ:- RabbitMQ is lightweight and easy to deploy on premises and in the cloud. It supports multiple messaging protocols. RabbitMQ can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements
- Celery:- Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well
- Ionic Cross Platform Mobile App:- Ionic’s open source Framework and developer-friendly tools and services power apps for some of the world’s best-known brands - from highly successful consumer apps like Sworkit, Untappd and Dow Jones MarketWatch, to mission-critical apps supporting Nationwide, Amtrak, and NASA.
- MongoDB:- MongoDB is a cross-platform document-oriented database program. It is issued under the Server Side Public License version 1, which was submitted for certification to the Open Source Initiative but later withdrawn in lieu of SSPL version 2
- MariaDB:- MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. Development is led by some of the original developers of MySQL
- Istio:- Istio is an open source independent service mesh that provides the fundamentals you need to successfully run a distributed microservice architecture
- Weavenet:- visualising kubernetes cluster
If you want a quick walkthrough of the end result, a video is available here
- From your terminal type
$ sudo nano /etc/hosts
- Type in your ICP ip and provide a dns name, quit and save the file
- Go to Docker prefernces
- Navigate to Daemon tab, click on + button underneath insecure registry and add an entry “:8500”, click Apply & Restart button to restart Docker service.
- In your terminal type
$ docker login <icpdns>:8500
- Booking Microservice
$ cd booking-microservice
$ npm i
$ docker build -t booking-microservice --no-cache .
$ docker tag booking-microservice <icpdns>:8500/default/booking-microservice
$ docker push <icpdns>:8500/default/booking-microservice
- Listing Mongo Microservice
$ cd listing-mongo-microservice
$ npm i
$ docker build -t listing-mongo-microservice --no-cache .
$ docker tag listing-mongo-microservice <icpdns>:8500/default/listing-mongo-microservice
$ docker push <icpdns>:8500/default/listing-mongo-microservice
- Authentication Microservice
$ cd login-microservice
$ npm i
$ docker build -t login-microservice --no-cache .
$ docker tag login-microservice <icpdns>:8500/default/login-microservice
$ docker push <icpdns>:8500/default/login-microservice
- Email Microservice
$ cd celery
$ docker build -t celery --no-cache .
$ docker tag celery <icpdns>:8500/default/celery
$ docker push <icpdns>:8500/default/celery
- Odm Microservice
$ cd odm-microservice
$ npm i
$ docker build -t odm-microservice --no-cache .
$ docker tag odm-microservice <icpdns>:8500/default/odm-microservice
$ docker push <icpdns>:8500/default/odm-microservice
- Angular Frontend
under src/app/provider/provider.ts. Find url and change it to your icp ip
$ cd icp-frontend-new
$ npm i
$ docker build -t angular --no-cache .
$ docker tag angular <icpdns>:8500/default/angular
$ docker push <icpdns>:8500/default/angular
- Ionic Frontend
under src/app/provider/provider.ts. Find url and change it to your icp ip
$ cd icp-mobile
$ npm i
$ docker build -t ionic --no-cache .
$ docker tag ionic <icpdns>:8500/default/ionic
$ docker push <icpdns>:8500/default/ionic
- Map Microservice
$ cd map-microservice
$ npm i
$ docker build -t map --no-cache .
$ docker tag map <icpdns>:8500/default/map
$ docker push <icpdns>:8500/default/map
Find all your images in
https://icpip:8443/console/manage/images
- Login to your icp instance by going to
https://icpip:8443
- Click on configure, click on copy, and paste all these commands in your terminal
- Login to IBM Cloud Private by going to this link
https://icplink:8443
-
Click on
Platform
and chooseStorage
, then click onCreate PersistentVolume
-
Provide the name
shared
for persistance volume -
Provide storage capacity for around
5GB
-
Access mode change to
Read Write Many
-
Storage type to
HostPath
-
Click on parameters tab and add the follow parameters
path: /anypath
- Click on create
Create Persistant volume using the steps above for
- DB2
- MariaDB
- MongoDB
- RabbitMQ
- ODM
- Go to
Catalog
and filteristio
- Choose target namespace as istio-system
Enable Grafana
Enable Prometheus
Enable Servicegraph
Enable Tracing
Enable Kiali
- Click on Install
- Navigate to
icp-backend/configMaps-secrets-istio-calico/kiali
and run
$ kubectl apply -f secret.yaml
- Check if Istio isd installed properly
$ kubectl get pods -n istio-system
- Go to
Catalog
and filterdb2
- Click on configure, fil up the required field and deploy
- Follow this tutorial to deploy db2 in IBM Cloud Private
Make sure your Table name is "Sample"
Make sure your username and password is "admin"
Deploy as clusterip
- ssh to db2 pod
$ kubectl exec -it <podname> bash
- switch the user you have created
$ su - <username>
- Connect to SAMPLE db
$ db2 connect to SAMPLE
- Create UserData table to store user information
- User Table
db2 CREATE TABLE "SAMPLE.UserData (UserID int NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) , LastName varchar(255) NULL , FirstName varchar(255) NULL, Location varchar(255) NULL, Email varchar(255) NULL, Password varchar(255) NULL, Age int NULL, Tier varchar(255) NULL, PRIMARY KEY (UserID))"
- Go to
Catalog
and filtermariadb
- Click on configure, fil up the required field and deploy
Make sure your Table name is "Sample"
Make sure your username and password is "admin"
deploy as ClusterIP
- ssh to mariadb pod
$ kubectl exec -it <podname> bash
- Get in to mysql cli
$ mysql
- Connect to SAMPLE db
$ use SAMPLE
- Create Booking Table
- Booking Table
CREATE TABLE SAMPLE.Booking (BookingID MEDIUMINT NOT NULL AUTO_INCREMENT,TS TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL , Checkin varchar(255) NOT NULL, OfferNamePricing varchar(255) NOT NULL, OfferTypePricing varchar(255) NOT NULL , CostPricing varchar(255) NOT NULL, OfferNameUpgrade varchar(255) NOT NULL, OfferTypeUpgrade varchar(255) NOT NULL , CostNameUpgrade varchar(255) NOT NULL, UserID INT NOT NULL, FlightID varchar(255) NOT NULL , PRIMARY KEY (BookingID));
- Go to
Catalog
and filtermongodb
- Click on configure, fill up the required field and deploy
Make sure your username and password is "admin"
deploy as ClusterIP
- Go to
Catalog
and filterrabbitmq
- Select
RabbitMQ
, ClickConfigure
, fill the form and click on deploy
use clusterip
- Go to
Catalog
and filterodm
- Select
odm
, ClickConfigure
, fill the form and click on deploy
-
Go to
http://icpip:odmport/teamserver/faces/login.jsp
, and login with username:-rtsAdmin
, and passrtsAdmin
-
Click on
Configure
tab, then click onimport project
. Select the zip file underodm-microservice
folder -
Go to
http://icpip:odmport/decisioncenter/t/library
, and login with username:-rtsAdmin
, and passrtsAdmin
-
Select
New Release
fromICPAirlines-Rules
, then selectICPAirlinesDeployment
and clickdeploy
- UID is ur database username
- PASSWORD is your database password
- UIDMARIADB is your mariadb username
- PASSWORDMARIADB is your mariadb password
- MONGOUSERNAME is your mongodb username
- MONGOPASSWORD is your mongodb password
- SECRET is your unique secret you give for your app for jwt authentication
- EMAILUSERNAME is your gmail email username from which email would be sent
- EMAILPASSWORD is your email password of your gmail email
- Navigate to
secrets
folder inconfigMaps-secrets/secrets
- Deploy secrets to kubernetes, navigate to folder icp-backend/configMaps-secrets-istio-calico/secrets
$ kubectl create -f secrets.yml
- If you need to redeploy with certain changes
$ kubectl apply -f secrets.yml
NOTE:- all these are base64 represenation encoding.
$ echo -n 'admin' | base64
YWRtaW4=
- DATABASE:- is your database name, which should be SAMPLE
- PORT:- is your exposed db2 port from port 5000, get this port by running and finding db2 service
- HOSTNAME:- is your db2 service name of db2
- ODM:- is your ODM api, replace dns with your service name of odm
- CELERY_RESULT_BACKEND:- replace dns with ur rabbitmq service name
- HOSTNAMEMARIADB:- replace with mariadb servicename
- HOSTNAMEMONGODB:- replace with mongodb servicename
- APPID:- your here map appid
- APPCODE:- your here map appcode
- Booking Microservice
$ cd booking-microservice/chart
$ helm install ./booking-microservice-0.1.0.tgz --name="bookingsvc" --tls
- Listing Microservice
$ cd listing-microservice/chart
$ helm install ./listing-microservice-0.1.0.tgz --name="listingsvc" --tls
- Authentication Microservice
$ cd login-microservice/chart
$ helm install ./login-microservice-0.1.0.tgz --name="loginsvc" --tls
- Celery Microservice
$ cd celery/chart
$ helm install ./celery-0.1.0.tgz --name="celerysvc" --tls
- Odm Microservice
$ cd odm-microservice/chart
$ helm install ./odm-microservice-0.1.0.tgz --name="odmsvc" --tls
- Map Microservice
$ cd map-microservice/chart
$ helm install ./map-microservice-0.1.0.tgz --name="mapsvc" --tls
- Angular Frontend
$ cd icp-frontend-new/chart
$ helm install ./angular-microservice-0.1.0.tgz --name="angular" --tls
- Ionic Frontend
$ cd icp-mobile/chart
$ helm install ./ionic-microservice-0.1.0.tgz --name="ionic" --tls
- Make sure you have installed ionic and cordova
$ npm i -g ionic cordova
- For IOS, make sure you have installed XCODE. For Android, make sure you have installed Android Studio.
- For IOS, run
$ ionic cordova prepare ios
- For Android, run
$ ionic cordova prepare android
- Navigate to
icp-backend/configMaps-secrets-istio-calico
- kubectl apply -f istio/
- Booking Microservice [:31380/bookingsvc/]
- Listing Microservice [:31380/listingsvc/]
- Authentication Microservice [:31380/loginsvc/]
- Angular Frontend [:31380/icpairways/]
- Celery Microservice [:31380/emailsvc/]
- Odm Microservice [:31380/odmsvc/]
- Map Microservice [:31380/mapsvc/]
Documentation of all the backend endpoints is available here