CI/C

How to Create CI/CD Pipeline using Devops Tools ? 🧠 🧠 🧠

Kaushal Soni

--

Hola Guys ! 🖐 🖐 🖐

I hope you all healthy 💪 I am again with my new blog, but this time it is in Devops Domain. So, I think you must be excited. 🤩 🤩 🤩

This blog is for those who want to create CI/CD ( Continuous Integration / Continuous Development ) Pipeline with DevOps Tools like : Jenkins, Kubernetes and Docker and SDM tools GitHub and Git. 🥳 🥳 🥳

So, lets start step by step. 👣 👣 👣

First we will discuss brief about these tools. 👀 👀 👀

Devops Tools

Technology Tools Used : 🩸 🩸 🩸

  1. Git
  2. GitHub
  3. Jenkins
  4. Docker
  5. Kubernetes

Now moving ahead and first of all discuss our use-case. 🥽 🥽 🥽

Use-Case brief Description : ⚡️⚡️⚡️

🔥 Create a container image that’s has Jenkins installed using Dockerfile Or You can use the Jenkins Server on RHEL 8/7.

🔥 When we launch this image, it should automatically start the Jenkins service in the container.

🔥 Create a job chain of job1, job2, job3, and job4 using build pipeline plugin in Jenkins.

🔥 Job1: Pull the GitHub repo automatically when some developers push the repo to GitHub.

🔥 Job2 :
⭐️ 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 the testing team could perform the testing on the pod.

⭐️ Make the data to remain persistent (If the server collects some data like logs, other user information ).

🔥 Job 3: Test your app if it is working or not. If the app is not working, then send an email to the developer with error messages and redeploy the application after the code is being edited by the developer.

CI / CD Development

Procedure : 🌫 🌊 🌊

  1. First of all we install all tools in our OS.
  2. Create Test web material for hosting and upload on github .
  3. Create CI/CD Pipeline which start with GitHub and end with Kubernetes.
  4. Test our Pipeline and website. ( *Not included in this blog*)

Before proceeding ahead, let’s consider my current OS environment ( which definitely different from your OS environment), so, my existing environment contains :

✨ I am using RedHat Enterprise Linux 8 as my base operating system in VirtualBox for Operational work (hosting website).

✨ In my base OS, Jenkins,docker and Kubectl (Kubernetes Client)is already. Don’t worry I will show you how to install and set these in a few minutes.

✨I am using Minikube in VirtualBox as a Kubernetes server.

✨ For Development work, I am using Git in my Windows system to develop the code and to upload it to GitHub.

Let’s Start with installation of the tools : ⚡️⚡️⚡️

It’s very easy to install above mentioned tools. We will start with installation of tools one by one. You just need to run a few commands for each program to setup. I am providing the installation procedure link, just copy those commands and run in terminal. 🧩 🧩 🧩

( 📌 NOTE :You can also use single command : yum install docker-ce — nobest -y )

Great by this you can successfully install all required tools. Next, you need to copy 3 files from your Windows OS to RHEL8 to connect the Kubectl with Minikube. Also before doing that install the Minikube and start it.

In windows go to C:\Users\username\.minikube and copy the “ca.crt” file. Next go to C:\Users\username\.minikube\profiles\minikube and copy the “client.crt & client.key” file. Next paste them in the “/root/” folder in the RHEL8. Finally you need to create the configuration file for Kubectl so that it can connect to Minikube. In below you can see the configuration file. The file name should be “config”, be careful and don’t give any extension in the name. Next copy this file in the “/root/.kube/” folder and Done.

Now, after this our environment is ready for CI/CD Pipeline. Now we will create our website code.

Website Development and SCM 🕒 🕓 🕔

Now we will create a website and upload that on GitHub (optional using git). I created one repository and connect it with my local git command of windows for continuous development of the code and uploading it. First I created github repository amd then attach it with local git.

Screenshot :

As this blog is based on CI/CD pipeline automation, thatswhy i am referring many initial setup, otherwise blog become too long. As our code and environment is ready and fully configured, So, without wasting time let’s move to our use-case.

CI/CD Pipeline Configuration 🕒 🕓 🕔

As we uploaded the code over GitHub in a repository. (as shown in below scrrenshot )

Github Repo

Now we build Jenkins environment by using dockerfile. ✒️✒️✒️

FROM centos
RUN yum install sudo -y
RUN sudo yum install wget -y
RUN yum install git -y
#Jenkins
RUN sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
RUN yum install java-11-openjdk.x86_64 -y
RUN yum install initscripts.x86_64 -y
RUN yum install jenkins -y
RUN echo -e "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
#Kubernetes
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN cp ./kubectl /usr/local/bin/kubectl
RUN cp ./kubectl /usr/bin/
RUN mkdir /root/.kube
COPY client.key /root/.kube
COPY client.crt /root/.kube
COPY ca.crt /root/.kube
COPY config /root/.kube
CMD /etc/rc.d/init.d/jenkins start && /bin/bash

We will build the following docker file with command : ✒️✒️✒️

docker built -t name:version dockerfile_location
Image Creating
Image Successfully created

Once the image created check the image and create container with commands : 🔍 🔍 🔍

docker image ls             # to list images
docker run -dit -p 10000:8080 --name any_name ks_jenkins:v1

Once the container created attach it to get password of the jenkins. So, to attach use command : 🔍 🔍 🔍

docker attach container_name
Container attached
Jenkins first Password

Now we start jenkins server on any browser and installed all plugins.

As Jenkins is successfully created 🎯, so now we start Jenkins and configure Jobs using browser. 🥁 🥁 🥁

So, Now we start our pipeline configuration with Jenkins Jobs Configuration :

🧲 NOTE : First give Jenkins root access, so that it can manage Linux OS. So, for that we either manually give access by edit “sudoers” file or by using command : “ echo ‘jenkins ALL=(ALL) NOPASSWD:ALL’ >> /etc/sudoers

Jenkins Job 1 configuration : ⚙️⚙️⚙️

First we add git plugin to our Jenkins : (skip this step if git plugin already set in your Jenkins )

Go to jenkins and click on “Manage Jenkins => “Manage Plugins” => available => search for “git” and Install the git plugin.

Now create JOB 1 ⚙️

Go to Jenkins Dashboard and click on “New Item” => give name “Job1” => click on Freestyle Project => then ok.

Next, follow the below-mentioned screenshots and put the required information.

JOB 1 configuration are as follows : ⭐️⭐️⭐️

Screenshot : 📷 📷 📷

Job 1 ( General )
Job 1 SCM
Job 1 Build Trigger
Job 1 Execute shell

I hope screenshots are enough to explain everything. As here I used poll SCM, you can use any trigger.

Now our JOB1 is successfully created, so let’s configure Job 2 .

Jenkins Job 2 configuration : ⚙️⚙️⚙️

Now we create our cluster using Kubernetes with the help of Jenkins. The Yaml script will be given below :

Cluster Yaml File

so, now we create Job 2 ⚙️

Go to Jenkins Dashboard and click on “New Item” => give name “Job1” => click on Freestyle Project => then ok.

Next, follow the below-mentioned screenshots and put the required information.

JOB 2 configuration are as follows : ⭐️⭐️⭐️

Job 2 build Trigger

From screenshot, we successfully create Job 2. Now we check our service by command (From windows cmd ) :

run command : ⭐

minikube service list
Service list

Now website hosted. So, go to the browser and check if your website is working or not. 👀 👀 👀

Jenkins Job 3 configuration : ✍️✍️✍️

Now, we create Job 3 which check whether the website is working or not. If website not work then it message us on gmail. So, to configure Job 3 first we have to set email plugin as per this article :

After configuration we create job 3 as per following scrrenshot : ✍️

Job 3 Build Trigger
Job 3 Execute Shell

Hense, by this our configuraton done. 🤝 🤝 🤝

The pipeline build pipeine view is mentioned below : 👇 👇 👇

CI/CD Pipeline Build Pipeline View

Testing Site : 🔍 🔍 🔍

On testing site we get that site is working successfully. ❣️❣️❣️

Hence, we have successfully done our task. 🎯🎯🎯

That’s all ! ⭐️⭐️⭐️

So, now it’s time to say Goodbye. Now, we will meet soon , in my upcoming blog, until that be happy and safe. 🤗 🤗 🤗

If you like my blog and wants such blog follow me on medium. 👍👍👍

In upcoming days I am going to publish lots of articles on Cloud Computing Technologies, aws, devops, hadoop and many case-study, So definitely follow me on Medium. 👀👀👀

Here is my LinkedIn profile link and if you have any queries definitely Comment. ✍️✍️✍️

--

--

Kaushal Soni

YouTuber || Instructor & Teacher || Technical Content Writer || MLOps || DevOps || Hybrid Multi Cloud || Flutter || Python || Arth Learner || Technology Lover