DevOps-Project-3
This article contain complete integration of git , github , jenkins , Kubernetes for deploying the web page by automation. I have launch complete environment for jenkins process using Dockerfile.
Task
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. Job1 : Pull the Github repo automatically when some developers push repo to Github.
5. Job2 :
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 ( If server collects some data like logs, other user information )
6. Job3 : Test your app if it is working or not.
7. 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
There is two section 1. Operation section 2. Developer section
1.Operation Section
The DevOps role pulled operations into the team, including ownership of the test servers, concerns about rollout and managing the rollout itself. A team that is pursuing DevOps likely owns responsibility for production servers, including monitoring and managing those servers.
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 plugin in jenkins.
JOB-1
- 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 impormation at every minute.
- I am copying all the data in the folder /Job1
JOB-2
- This job contain some kubectl commands that will deploy the web page on the top of kubernetes.
- and copying file in the directory (/var/www/html) of pod that contain code of web page.
- this job will depends on the job1
JOB-3
- According to given instruction for job3 . i am using status code and exit code in the job3. if any error will we in the code it will automatically stop with exit 1 and it will fail the job3 .and if everything is good then it will stop with exit 0 and it will not fail the job3. and job2 will trigger the job3.
- this job depends on job2
JOB-4
Before creating job4 we need to configure email. for this go to configuration system and give some necessary information as given below.
- Just i am putting my email id in the email Notification section and i have give less security power to my email which is must to send email.
- and in the attach build log we can put attach the log of console output
- this job depends on job3 .
All the job is completed, so I have created a build pipeline. my all four 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.
2.Developer section
DevOps Engineer works with developers and the IT staff to oversee the code releases. They are either developers who get interested in deployment and network operations or sysadmins who have a passion for scripting and coding and move into the development side where they can improve the planning of test and deployment.
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.
once the job1 successfully done job2 will be trigger.
here we can access our webpage using "<minikubeIP:32000"
here i am sharing console output of all the jobs
JOB-1
JOB-2
JOB-3
JOB-4
and if job3 will be failed then we will get this type of message
I have done with all the setup