DevOps Assembly Lines Task #3
Task Description:
- Create container image that’s has Jenkins installed using docker file.
- When we launch this image, it should automatically starts Jenkins service in the container.
- Deploy a container of this image on top of Kubernetes where we use Kubernetes resources like Pods, ReplicaSet, Deployment, PVC and Service.
- Create a job chain of job 1, job2, job 3 and job 4 using build pipeline plugin in Jenkins
- Job 1: Pull the Github repo automatically when some developers push repo to Github.
- Job 2: 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 )
- Expose your pod so that testing team could perform the testing on the pod.
- Make the data to remain persistent ( If server collects some data like logs, other user information )
- Job 3: Test your app if it is working or not.
- Job 4: 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.
Creating Jenkins image:
- Create a text file named 'Dockerfile'.
- Now to create an image with it:
>> docker build -t jenkinsimage:v1 ws/
Running Jenkins container on Kubernetes:
YAML code to create a container with jenkins running on port no. 8080:
Now to start the Jenkins container using this file:
>> kubectl apply -f jenkins_pod.yml
>> Kubectl get all
This will deploy the jenkins pod successfully.
Now to get the IP where the jenkins service is running:
>> minikube ip
Now, to use jenkins web UI use minkubeIP:port_no.
To get your jenkins password to use web UI:
>> kubectl logs pod_name
In the logs we'll find the jenkins password.
To proceed further we will need to install git, email extension build pipeline plugins in Jenkins.
Creating Repository on GitHub:
- git clone https://github.com/suchitrasaksena/DevOps_task3.git
After creating the files:
- git add .
- git commit -m "first commit"
- git push -u origin master
- The repository will be created successfully.
The repository is successfully created.
Configuring Jenkins:
Job 1:
This job will automatically download the GitHub repository whenever developer pushes any changes.
Job 2:
This job will automatically run after successful completion of job 1 and start the apache pod to deploy the website.
YML file to create service for apache webserver:
YML file to create PVC for apache webserver:
YML file to create Deployment for apache webserver:
Job 3:
This job will run after successful completion of job 2 and will check if the deployed website has any errors.
Job 4:
This job will run after job 3 to notify the developer if the website has any errors via mail.
All the jobs execute successfully, here's the build Pipeline view:
The task is successfully completed, and the website is deployed successfully.
Thanks for reading, feel free to leave your suggestions to improve this setup.