DevOps Assembly Lines Task #4
Task Description:
Create A dynamic Jenkins cluster to achieve this setup:
- Create container image that’s has Linux and other basic configuration required to run Slave for Jenkins. ( example here we require kubectl to be configured )
- When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.
- Create a job chain of job 1 & job 2 using build pipeline plugin in Jenkins:
- Job 1: Pull the GitHub repository automatically when some developers push repo to GitHub and perform the following operations as:
- Job 1: Pull the GitHub repository automatically when some developers push repo to GitHub and perform the following operations as:
- Job 2: ( Should be run on the dynamic slave of Jenkins configured with Kubernetes kubectl command): Launch the application on the top of Kubernetes cluster performing following operations:
- Job 2: ( Should be run on the dynamic slave of Jenkins configured with Kubernetes kubectl command): Launch the application on the top of Kubernetes cluster performing following operations:
- If launching first time then create a deployment of the pod using the image created in the previous job. Else if deployment already exists then do roll out of the existing pod making zero downtime for the user.
- If Application created first time, then Expose the application. Else don’t expose it.
Creating Repository on Github:
Commands:
Index.html file:
Dockerfile:
The repository will be created successfully.
Setup in Linux Environment:
- setenforce 0
- systemctl stop firewall
- systemctl start Docker
- systemctl start httpd
- systemctl start Jenkins
Creating image with kubectl configured:
Docker file to create the image:
Now to create an image using this Docker file:
>> docker build -t kubernetes-env:v1 ws/
Image will be created successfully created.
Configuring Jenkins:
Job 1:
This job will download the repository from GitHub whenever developer pushes some changes to the repository and will check for html files and then it will build the required image for the code using the docker file from the repository.
Job 2:
This job is the downstream of job 1 and after successful execution of job 1 this job will start the deployment of the website if the deployment is not already running or else it will roll the new update on the already running containers.
Both the jobs run successfully and the website is deployed successfully.
The task is complete!
Thanks for reading, do leave your reviews and suggestions to improve this setup.