Search this site
Embedded Files
Debashis Sahu
  • About Me
  • PROJECTS
  • Publications
  • Posters & Talks
  • Professional Documents
    • Certificates & Marksheets
    • Postdoc Experiences
    • PhD Thesis
Debashis Sahu
  • About Me
  • PROJECTS
  • Publications
  • Posters & Talks
  • Professional Documents
    • Certificates & Marksheets
    • Postdoc Experiences
    • PhD Thesis
  • More
    • About Me
    • PROJECTS
    • Publications
    • Posters & Talks
    • Professional Documents
      • Certificates & Marksheets
      • Postdoc Experiences
      • PhD Thesis
  1. Step-1: Set Up Webhooks in GITHUB repository through Jenkins for automatic copy of the updated code from the GITHUB repository to the local computer/AWS cloudshell instantly

  2. Step-2: If step-1 is passed, Dockerize the code and test the running code at port 80 & 85 specifically on a AWS instance

  3. Step-3: If step-2 is passed, the code will be deployed on Kubernetes running on AWS platform in one shot as a fully automatic way in Jenkins (option-1: freestyle job & option-2: pipeline job)

Step-1

Pushing the codes  from AWS Cloudshell to github repository “git-repo”. The code files are present inside "DevOpsProfessional" folder.

Here, AWS CloudShell is considered as the local machine. By the way, AWS EC2 instance is created as the remote machine. Our target is the moment we push the code into the the Github repository (git-repo), the Jenkin will copy the code from Github repository to the remote AWS EC2 instance

After pushed the codes: screenshot of github repository below:

Testing the webhooks: Here the code will be copied into aws instance at the moment of change the code in GIThub

First a webhooks is created in Github account. The successful creation of the webhook is mentioned in the below screenshots.

By the way the webhook is created with Jenkins earlier. The set up of Jenkins for this automation is mentioned later here !!

The html code (index.html file) is changed. The details of the change (DSAHU **) of index.html file is given below screenshot.

Next, the changed file is pushed into the github repository which is shown in the below screenshot

Here, the confirmation from the automation of the webhooks is mentioned below in screenshot.

The details of Jenkins configuration set up is mentioned below screenshot

The successful completion of the Jenkins job is cleared from the Jenkins Job Console Output: Automatically copy code from Github repository (git-repo) to Local machine. See below screenshot

Here the verification steps that ensure: our code file (index.html) is copied into the instance folder /var/lib/jenkins/workspace/Evaluation

Screenshots are mentioned below:

Step-2

Run Docker Container at port 80:

sudo docker images

sudo docker run -it -p 80:80 evaluation:latest

Testing running code on browser using public IP of AWS instance

Run Docker Container at port 85

Before testing on port 85, we have to first update the inbound rule of security group for port range 85 for the instance. The screenshot is mentioned below:

sudo docker run -p 85:80 -t -d evaluation:latest

The Docker containerized code is now running on port 85 which is verified on browser IP address as below

Test Automation: Run Docker Container at port 85 using Jenkins Job

Changing code file "index.html" at AWS CloudShell as below

Push the changed code into Github repository:

git add .

git commit -m "webhook test via jenkins"

git push origin master

Docker Container is automatically running on port 85 via Jenkins sequential Jobs. The screenshot is mentioned below.

docker ps -a

docker images

The successful completion of Jenkins job is confirmed from the Console Output of the Jenkins Job. Screenshots are given below

Step-3

Deploy Kubernetes

Option-1: Using Freestyle Upstream serial Jobs

We have created three freestyle jobs on jenkins: 

1. Build Dokcer (to build docker image) 

2. Push_Dockerhub (push the docker image to Dockerhub)

3. Deploy_EKS (Pull the docker image from Dockerhub and deploy it on Kubernetes)

Job orders: 1--> 2--> 3



The screenshots of three Jenkins Job set up and the successful completion of three jobs are given below

The Console Output of three Jenkin jobs are mentioned below

Kubernetes nodes running under cluster "mirror333"

mirror-333 name containg two kubernetes nodes are in running state (screenshots below)

Updating the inbound rule for the security group corresponding to the kubernetes nodes

Now Testing the codes on Browser: public ip of kubernetes node-1

Now Testing the codes on Browser: public ip of kubernetes node-2

Option-2: Jenkins Pipeline to deploy Kubernetes

we have performed here using Pipeline script instead of using any freestyle job in Jenkins. 

pipeline script :


pipeline {

    agent any

    

    stages {

        stage("Clone code from GitHub") {

            steps {

                script {

                    checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'git_credentials', url: 'https://github.com/dsahu87/git-repo']])

                }

            }

        }

        

        stage('Build Docker Image') {

            steps {

                script {

                    sh 'docker build -t dsahu87/evaluation .'

                }

            }

        }

        

        stage('Deploy Docker Image to DockerHub') {

            steps {

                script {

                    sh 'docker login -u dsahu87 -p deba@1234'

                    sh 'docker push dsahu87/evaluation'

                }

            }

        }

        

        stage('Deploying App to Kubernetes') {

            steps {

                script {

                    sh ('aws eks update-kubeconfig --name mirror333 --region ap-south-1')

                    sh "kubectl get ns"

                    sh "kubectl apply -f deployment.yml"

                    sh "kubectl apply -f service.yml"

                }

            }

        }

    }

} 

Console Output of Jenkin Job

On Terminal: Verifying the deployments on Kubernetes

Kubernetes nodes running under cluster "mirror333"

Testing the code running on Docker Container from browser: for kubernetes node-1

Testing the code running on Docker Container from browser: for kubernetes node-2

Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse