DevOps-Project-6

DevOps-Project-6


finally, I have completed my DevOps automation task...

This article contains complete integration of git, GitHub, Jenkins, Kubernetes for deploying the web page using full automation with groovy code. I have to launch a complete environment for Jenkins process using Dockerfile.

Task-6

1. Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7

2. When we launch this image, it should automatically start Jenkins service in the container.

3. Create a job chain of job1, job2, job3, and job4 using the build pipeline plugin in Jenkins 

4. Job2 ( Seed Job ) : Pull the Github repo automatically when some developers push repo to Github.

5. Further on jobs should be pipeline using written code using Groovy language by the developer

6. Job1 :  

  1. By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed )

  2. Expose your pod so that testing team could perform the testing on the pod

  3. Make the data to remain persistent using PVC ( If server collects some data like logs, other user information )

7. Job3 : Test your app if it is working or not.

8. Job4: if the app is not working, then send email to developer with error messages and redeploy the application after code is being edited by the developer

The prerequisite for this project is

  • I have windows operating system in which I have already install git bash,
  • Kubernetes and kubectl have configured.
  • I have Redhat 8 operating system which is running on the top of windows by virtualization. in this, my Docker is running.
  • for Source Code Management i have GitHub account and i have also account on hub.docker.com where i can push my images.
  • and i have stop the firewall using systemctl stop firewalld and selinux using setenforce 0 so that there will no issue in connectivity between two VM.

__________________________________________________________________________

Start Building

First, we have to create a Jenkins Docker image in which we have to configure kubectl too.

  • In the below screenshot I have created a Dockerfile in which i have install all the the software that will use in my project.
  • I am copying some file like client.key, ca.crt , client.crt these are the key and certificate for configure the kubectl in another vm. because my kubernetes and kubectl is install in my windows operating system. now i am configuring kubectl in another vm that's why i need these files.
No alt text provided for this image
  • i am copying another file which is myinfo
No alt text provided for this image


  • this is file is for configure the kubectl command. it include all the information which is required the kubeclt to run in another vm like: ip and port number of minikube and location of keys and certificates.

Build this image using command

"docker build -t devops . "

No alt text provided for this image


Launch a container using this image using command

"docker run -dit -p 8086:8080 --name jenkins devops:v2"

No alt text provided for this image

we can get the initial password of Jenkins using command

docker exec <container name> cat /var/lib/jenkins/secrets/initialAdminPassword" as shown above on the image.

now browse and access the Jenkins using Ip of base os and port no

192.168.43.163:8080

No alt text provided for this image

now complete setup is done of jenkins. so we can start creating job in jenkins

before start creating the job i have installed github , build pipeline, email Notification and job dls plugin in jenkins.

JOB-1

  • this is my seed job , it will create others job.
  • In job i am putting my github repository url in git section sp that i can download all the code uploaded by developer.
  • I am scheduling my job using pollscm it will go to github and check the information at every minute. if any new data will be uploaded by the developer it will automatically download the code.
  • I am copying all the data in the folder /Devops6
No alt text provided for this image
No alt text provided for this image


  • in DSL script i have written Groovy code to create job2 and job3.
No alt text provided for this image


job("JOB-2") {
description("This job will launch the pods and deploy the code")

	triggers {  
	upstream('JOB-1', 'SUCCESS')
	}


  steps {
  shell('cd /devops6\nkubectl create -f webpage.yml\nsleep 15\npodename=$(kubectl get pods -o=name | grep webdeploy | sed "s/^.\\{4\\}//")\nkubectl cp /devops6/mycode  $podename:/var/www/html')
}

}



job("JOB-3") {


	triggers {  
	upstream('JOB-2', 'SUCCESS')
	}


 steps{

  shell('status=$(curl -o /dev/null -s -w "%{http_code}" http://192.168.99.110:32000/mycode/myweb.html)\nif [[ $status == 200 ]]\nthen\nexit 0\nelse\nexit 1\nfi')

}
  
    publishers {
        extendedEmail {
            recipientList('pp732298@gmail.com')
            defaultSubject('Oops')
            defaultContent('Something broken')
            contentType('text/html')
            triggers {
                beforeBuild()
                stillUnstable {
                    subject('Subject')
                    content('Body')
                    sendTo {
                        developers()
                        requester()
                        culprits()
                    }
                }
            }
        }
    }

  
  
}

After creating job3 we need to configure email. for this go to configuration system and give some necessary information as given below.

No alt text provided for this image


All the job is completed, so I have created a build pipeline. my all three jobs are dependent to each other. so as soon as developer will push the code on github then job1 will automatically will start and other job also will start.

So here developer written code in a file webconfig.yml to deploy web page on the top of kubernetes.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


and some others files that contain some html code

and then push it github repository

as soon as developer push the code to github job1 will trigger because pollscm checking information at every minutes.

here we can access our webpage using "<minikubeIP:32000"

JOB-2 created by seed job using groovy code

No alt text provided for this image
No alt text provided for this image


JOB-3 created by seed job using groovy code

No alt text provided for this image
No alt text provided for this image


No alt text provided for this image

console output of all the job

No alt text provided for this image

Build all job pipeline

If job-3 will be failed

No alt text provided for this image

we will receive mail on the email.

I have done with all the setup

Thank You for reading this article.................

To view or add a comment, sign in

More articles by Prakash Choudhary

Explore content categories