Skip to content

Project Milestone 3

sravya160597 edited this page Apr 7, 2021 · 25 revisions

Tasks

Dockerized all Microservices and pushed them to the docker hub

Established CI/CD pipeline using Jenkins

Deployed containerized microservices using OpenShift

Automation Scripts for management of VMs and Deployment of OpenShift

Deployed entire system on vanilla Jetstream VMs

For milestone 3, Our first step was to create dockerized versions of each micro-service and the front-end. After that, we integrated all microservices to be continuously deployed using Jenkins. Thus, Jenkins provided continuous deployment by pushing every new git commit into the docker hub (docker registry), after which Each new build inside the docker hub will be deployed into the Openshift cloud container & orchestration platform.

Flow

Flow description:

  1. Push commit on Github repo the new code
  2. This will trigger a new Jenkins build for building new docker images
  3. Jenkins will also check on the test cases written for that image before pushing the image on Docker Hub (part of CI)
  4. Once CI is done, Jenkins continuously deploys the new microservice images from docker Hub on the Openshift platform.
  5. Then Jetstream VM instance is created to provide the resources for the deployed services.

Getting Started

Steps to setup Jenkins CI/CD:

Jenkins instance is deployed at http://149.165.171.240:8080/

We have used Jenkins for our CI/CD that is deployed on a VM on the jetstream. We have also set up a GitHub webhook to automatically trigger builds when a push is made to specific branches. Each microservice has its own Jenkinsfile.

Download Plugins (only for local systems)

  1. Go to Manage Jenkins
  2. Click on Manage Plugins
  3. Search and Install the following plugins from the 'Available' Tab Docker; Nodejs; SSH; Publish over SSH; Git
  4. Restart Jenkins to apply the installed plugins

Add global configurations

  1. Go to Manage Jenkins -> Click on Global Configuration Tool -> Add Git installation

      Name: Default, Path to Git executable: git
    
  2. Add NodeJS installations

      Name: node, Leave everything else as default
    
  3. Add docker hub credentials by following this link Follow this tutorial to add your Docker credentials to ensure after the image is built, it is pushed to docker hub.

  4. Create a Job by selecting 'New Item' -> Enter Name -> Select Pipeline Job -> From Build Triggers select GitHub to hook trigger for GITScm polling

Building a pipeline :

• Definition: Pipeline script from SCM

• SCM: git

• Repository URL: https://github.com/airavata-courses/PixelGram

• Branches to build: developer

• Script path : pixelgram-image-service/jenkinsFile(or any service)

• Lightweight checkout: Checked

• Save

Below are the steps in our jenkins pipeline script,

Clone repository - getting the repository from github

Prepare repository - due to our folder structure (with the files being in a sub-directory), we need to process the folders in order to access the files.

Build repository - installing the dependencies using npm, mvn or pip.

Test repository - running the unit tests for the services

Building image - building the docker image using the Dockerfiles for each service

Pushing image - pushing the built images to Docker Hub

Deleting local image - cleaning up the local image so that dangling images do not consume space

Deploy on openshift - ssh'ing and applying the deployment/service config files to create a pod that runs the images in docker hub.

jobs screenshot jobs screenshot1

Achieving Continuous Deployment via jenkins

Unit Tests

Each service has a few unit tests that test whether the service is up and running. We have tried to keep the unit tests simple, yet effective enough to depict an actual deployment scenario. These unit tests can be found in each of the services. The unit tests need to be passed in order for the services to be deployed.

Kubernetes setup:

Each service has its own horizontal pod autoscaler/ingress/deployment/service config files that are applied on the Kubernetes master node. The gateway and the UI have external IP (LoadBalancer type service) ports as they should be able to be accessed from outside. Our rationale for making the Gateway externally available is so that applications that are hosted on another cloud service can still use the scrapbook APIs. All the other communication is internal, thus happens via their ClusterIP (internal) ports and will not be available to applications outside the Kubernetes cluster. An example of a Kubernetes config YAML is given here

Deployment:

The steps to create VMs and configure Kubernetes are given here.

VM Creation:

we used jetstream GUI to create a VM instance and configured the below parameters, cluster name, floating ip, number of nodes, flavor of the VMs and the name of the network. Needless to say, we have to install and authenticate the openstack API to work on our local system. Different security groups are created as the Kubernetes Master node requires different ports from the Worker nodes. By default TCP 22 port is open to allow SSHs. To use this script, one has to change the variables mentioned above.

Kubernetes Cluster Creation

Using this blog we have created Ansible scripts to set up the Kubernetes cluster. The script uses the node created in the previous section and installs Kubernetes on them. Then it assigns them roles using various security groups. The master node has port 8443 open for the Control Plane to be set up. By configuring the floating IP of the master node, the ansible script configures the Master.

Application Deployment:

Make a push to the developer branch and Jenkins will automatically deploy the whole application.

The production version is currently deployed at http://pixelgram.io/