DevOps-Project-6
This article contain complete integration of git , github , jenkins , Kubernetes for deploying the web page using full automation with groovy code . I have launch 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 starts Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using 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 app is not working , then send email to developer with error messages and redeploy the application after code is being edited by the developer
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 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.
- i am copying another file which is myinfo
- 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 . "
Launch a container using this image using command
"docker run -dit -p 8086:8080 --name jenkins devops:v2"
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.199:8086
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 developer it will automatically download the code.
- I am copying all the data in the folder /Devops6
- in DSL script i have written Groovy code to create job2 and job3.
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}" https://192.168.99.110:32000/mycode/satyam.html)\nif [[ $status == 200 ]]\nthen\nexit 0\nelse\nexit 1\nfi') } publishers { extendedEmail { recipientList('[email protected]') 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.
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.
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
JOB-3 created by seed job using groovy code
console output of all the job
JOB-1
JOB-2
JOB-3
If job-3 will be failed
we will receive this type of mail on the email.
I have done with all the setup
Student at ARTH - The School of Technologies
4 年Now I became totally jealous from you guys Sulekha . Suhaib Ansari Satyam Kumar Rakesh Mishra Babli Singh