Task - 4 DevOps Assembly Lines

Prathmesh Mandve
4 min readJul 25, 2020

Task Overview :

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:

a. Create the new image dynamically for the application and copy the application code into that corresponding docker image

b. 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:

a. 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.

b. If Application created first time, then Expose the application. Else don’t expose it.

Requirement for performing task :

So before we start we have to set the remote login for the docker services. for doing this we have to change the file /usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
𝘌𝘹𝘦𝘤𝘚𝘵𝘢𝘳𝘵=/𝘶𝘴𝘳/𝘣𝘪𝘯/𝘥𝘰𝘤𝘬𝘦𝘳𝘥 -𝘏 𝘧𝘥:// -𝘏 𝘵𝘤𝘱://0.0.0.0:4243 ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

"/usr/lib/systemd/system/docker.service"

After that we have to restart the docker services for applying the changes.

systemctl daemon-reload
systemctl restart docker

Step 1 :

In this step we have to create a Dockerfile that has web server installed. So when we push the html code it will be launched on the webserver.

Step 2 :

Then we have to create a Jenkins job which will download the code and Dockerfile from the github automatically after pushing it to the github.

Step 3 :

In this step ew will build our docker image from the file. And after building the image it will be pushed to docker hub.

Step 4 :

Now we need to a configuration of the kubectl, so we have to create a configuration file for this.

Now for creating the container image first we have to configure the kubectl by creating a local repo of kubernetes in our machine.

Now before we create a docker file for the kubectl we have to transfer client certificate and client key and to our machine so we can configure kubectl.

Step 5 :

And now we have to configure cloud for docker in our jenkins,so we will need docker plugin for this or it will not work.

Step 6 :

In this last step we have to create a jenkins job which will deploy the image.

So then we can scale the required replicas and kubernetes will monitor the pods for us.

We are at the end of the task.

Thanks for reading

--

--