Skip to content

Project 3

saiprasad-rane edited this page May 4, 2022 · 6 revisions

Kubernetes Setup

We have used terraform and OpenStack CLI for creating the instances. Ansible playbooks is used to connect the instances and run it to setup kubernetes. Connect the master node and run the yaml files for running deployment and services.

We have used a remote machine with ubuntu image. After opening the terminal, write the following commands:

  • Create SSH Key
 sudo su</br>
 ssh-keygen</br>
source <openrc.sh>
  • Once the Kubernetes is successfully installed in the cluster, we have to start the deployment and the services.

  • Once the setup is done we can test using this command:

ssh ubuntu@$IP
sudo su
kubectl get all

CI-CD Setup

We used Jenkins to integrate CI CD in our project. Following are the functionalities performed by Jenkins:

  • It will pull any changes made in any respective Github branch.
  • Once changes are pulled, it will create a new image and push it on specified docker hub.
  • It then performs the kubernetes deployment by performing the login and restarts the service which was updated.
  • Further it logs out of the docker hub.

Commands for the same are shown below:

pipeline {
   agent any
   environment {
      DOCKERHUB_CREDENTIALS=credentials('dockerhub-renuka-jenkins')
   }
   stages {
      stage('Docker Image Build') {
         steps {
            dir('app') {
               sh 'docker build -t persistenceservice .'
               sh 'docker tag persistenceservice:latest renukasrishti/persistenceservice:persistenceservice'
               sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
               sh 'docker push renukasrishti/persistenceservice:persistenceservice'
            }
         }
      }
      stage('Kubernetes Deployment') {
         steps {
            dir('app') {
               sh 'export KUBECONFIG=/home/exouser/.kube/config && kubectl apply -f persistence-service-secrets.yaml && kubectl apply -f mysql-pv.yaml && kubectl apply -f mysql-deployment.yaml && kubectl apply -f persistence-service-deployment.yaml && kubectl rollout restart deployment/mysql && kubectl rollout restart deployment/persistenceservice-deployment'
            }
         }
      }
   }
   post {
      always {
         sh 'docker logout'
      }
   }
}

Above code is for one of the service.
Similarly for each service, we have different Jenkins file.
Link can be found below:
https://github.com/airavata-courses/Viyad/blob/feature-api-gateway-CI-CD/Jenkinsfile
https://github.com/airavata-courses/Viyad/blob/feature-data-CI-CD/Jenkinsfile
https://github.com/airavata-courses/Viyad/blob/feature-persistence-CI-CD/Jenkinsfile
https://github.com/airavata-courses/Viyad/blob/feature-auth-CI-CD/Jenkinsfile

Screenshots have been attached for each CI CD:

Screenshot from 2022-05-03 18-31-11

Screenshot from 2022-05-03 18-31-49

Screenshot from 2022-05-03 18-31-56

Screenshot from 2022-05-03 18-32-10