DEVOPS TASK 4
Create A dynamic Jenkins cluster and perform task-3 using the dynamic Jenkins cluster.
Steps to proceed as:
1. 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 )
2. When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.
3. Create a job chain of job1 & job2 using build pipeline plugin in Jenkins
4. Job1 : Pull the Github repo automatically when some developers push repo to Github and perform the following operations as:
1. Create the new image dynamically for the application and copy the application code into that corresponding docker image
2. Push that image to the docker hub (Public repository)
( Github code contain the application code and Dockerfile to create a new image )
5. Job2 ( 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:
1. 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 rollout of the existing pod making zero downtime for the user.
2. If Application created first time, then Expose the application. Else don’t expose it.
---------------------------------------------------------------------------------------------------------------
Step 1: Dockerfile of SSH enabled image which has Kubernetes configuration
Config file used for Kubernetes:
Step 2: Docker files:
For apache webserver [here tagged and pushed in DockerHub as manaligorwani/apache-webserver-php:latest]
Docker file which copies the webpages and creates/updates the docker image [here tagged and pushed in DockerHub as manaligorwani/manali-php:latest], that same folder should have webpages to be deployed.
Step 3: Deployment file which creates pods using above image
Step 4: In Slave system, update /usr/lib/systemd/system/docker.service file, add "-H tcp://0.0.0.0:4243" in ExecStart variable to expose TCP port
Step5: Use the slave system's IP as DockerHost in the main system, to access the slave system's docker service from there.
Step 6: Start Jenkins with main system. Job1 pulls data from Github repository and copies in /web_data folder and that same folder is used to build/publish docker image with the help of slave system's dynamic node which is configured in Jenkins.
Step 7: Job2 is restricted to work in slave system's dynamic node
And this job runs only after successful completion of job1
Launches the deployment and exposes it.
Configuration of dynamic node in Jenkins:
Now, job1 runs as soon as something is uploaded or changed in the Github repo, and after successful completion of job1, job2 runs and launches deployment
When there is any change in Github repository it updates automatically, nothing is to be done manually.