DevOps AL task 4

DevOps AL task 4

In this task, task 3 is done using dynamic Jenkins cluster. The Jenkins master acts to schedule the jobs and assign slaves and send builds to slaves to execute the jobs. It will also monitor the slave state (offline or online) and getting back the build result responses from slaves and the display build results on the console output.

TASK DESCRIPTION:-

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.

In this task, I have used two rhel8 VMs. One working as master(192.168.99.103) and another as slave(192.168.99.104).

NOTE:- Make sure both VMs are in same network.

Now the first thing we have to do is edit /usr/lib/systemd/system/docker.service file so that it can accept all the IPs on the given port as shown below:-

No alt text provided for this image

After this we have to run following commands:-

systemctl restart docker
systemctl enable docker

After this if we run the command -> systemctl status docker, it will look like this

No alt text provided for this image

Exporting docker host so that slave(104) can connect to it:-

export DOCKER_HOST=192.168.99.103:4243

Now, we need to make a image which has all requirements needed to run jenkins-slave. For this we have to make a Dockerfile:-

No alt text provided for this image

Requirements to run jenkins-slave are -

1). Linux

2). SSH enabled

3). kubectl

4). user/password

5). Workspace

This is apache.yml file :-

No alt text provided for this image

This is config file:-

No alt text provided for this image

All the certificates and keys i.e., ca.crt, client.crt and client.key, will be transferred to the workspace using winscp.

Now it's time to build and push the image using command:-

docker build -t dockerhub_username/imagename:version .\
docker push dockerhub_username/imagename:version

After successfully push the image to dockerhub, we will start configuring jobs in Jenkins

JOB 1: 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 )

To create webhook so that job triggers as soon as some developer push code to github I have used ngrok.

No alt text provided for this image


No alt text provided for this image

GitHub link for Dockerfile and application ocde is given below:-

Now before configuring job 2 we will configure docker cloud.

NOTE:- We will need docker plugin to configure docker cloud.

No alt text provided for this image

Notice ip of slave node is given in Docker Host URI. We can test connection by clicking on it. If we everything is good then it will show version.

No alt text provided for this image

Here, I have given jenkins-slave image which is build above.

No alt text provided for this image

In SSH credentials we will give the credentilas which are configured in jenkins-slave image.

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:

  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.

No alt text provided for this image

Here, label which was given while configuring docker cloud will be given and triggering the job after job 1 has been build.

No alt text provided for this image

If the deployment already exists then update otherwise create and expose.

Now everything is done. As soon as developer pushes the code to github, job 1 automatically gets and this is the ouput of job 1:-

No alt text provided for this image
No alt text provided for this image

Ouput of job 2:-

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Output when deployment created first time:-

No alt text provided for this image

After updating:-

No alt text provided for this image
No alt text provided for this image

Build pipeline view:-

No alt text provided for this image

Thanks!

To view or add a comment, sign in

More articles by Tanisha Agrawal

  • Summer Training at LinuxWorld

    I am very happy to share that I underwent summer training for DevOps assembly lines from LinuxWorld Informatics Pvt…

  • Launching mysql-wordpress on EKS

    WHAT IS EKS? Amazon Elastic Kubernetes Service (Amazon EKS) is a managed service that makes it easy to run Kubernetes…

  • DevOps AL task 6

    This task is similar in every way to task 3 except in this task we are not creating jobs manually from Jenkins GUI…

  • Upgrading task 2 with Kubernetes

    Kubernetes, also written as k8s, is an open source container orchestration system for automating computer application…

  • Integrating Prometheus and Grafana on K8s (DevOps AL task 5)

    WHAT IS PROMETHEUS? Prometheus is a free software application used for event monitoring and alerting. It records…

  • DevOps Assembly Lines Task 2

    Task description:- 1. Create container image that has Jenkins installed using Dockerfile.

    2 Comments
  • Creating application using terraform and jenkins

    Task description:- 1. Create the key and security group which allow the port 80.

    6 Comments
  • DevOps Assembly Lines project

    In today's era, automation can be seen everywhere. Things which humans used to do are being done by machines and even…

Others also viewed

Explore content categories