SysopsMicro
Published in

SysopsMicro

DevOps CI/CD Pipeline with Jenkins, Kubernetes & GitHub: Part 1

How to set up Jenkins and CI/CD pipelines using GitHub?

source

I feel:

“DevOps is a must for all kinds of tech startups, small or big. It may be complex to start with but will make your life hell easy going forward and can save loads of time and energy for the organization to scale, scale and scale..”

Today we will look into how we can set up a CI/CD pipeline to automate the code deployment using the power of Jenkins.

In this part, we will cover :

  • How to build a Jenkins Docker image?
  • How to deploy the Jenkins image onto our local Minikube cluster?
  • How to run the deployed Jenkins image on our web browser?

Prerequisite Steps :

  • Install docker desktop
  • Create GitHub organization, give it a name, and fork all of the sample repositories from the given URL :

Once you are done with the above-mentioned steps, its time that we learn how to setup Jenkins in our local Minikube cluster cluster

How To Setup Jenkins on Our Minikube K8s cluster?

If you have forked all the repositories from my Github organization repository account, you will find one repo named:

So now you can simply clone the same using the following K8s command, let’s see step by step how to do so

I will be using my mac terminal to run all my bash commands

Step1: Start Minikube cluster :

Here, I am specifying a memory of 4 GB, because Jenkins is quite resourced intensive so please ensure you are starting the Minikube cluster with these extra flags.

$ minikube start — memory 4028
Fig 1.0: Start minkuibe

If you managed to successfully start the minukube you will see the output as shown in Fig 1.0

Then test if everything is fine by coining the below command

$ minikube status 
minikube status output

You should be able to see the output as shown above.

2. Clone the Sample repo:

Given below

In your local machine and keep it inside a folder named CICDdemo(you can keep whatever name to your liking )

3. Enter into the CICDdemo folder in your terminal using the below-given, “change directory” command

$ cd /Applications/K8s/CICDDemo

you will get to see jenkins folder which will have two files. If you further go inside the jenkins folder by changing the directory from your terminal, you will be seeing the below-given files.

  • jenkins.yaml
  • Dockerfile

As shown below,

fig 2.0

Now that you have cloned and are in the jenkins directory, it’s time to build the docker image of Jenkins.

3. Build Jenkins Docker Image:

We will be building a jenkins docker image using Dockerfile present inside the jenkins folder, by making use of the docker build image command, but before that, it is important to change the environment variable so that we can make use of the local docker-daemon service running inside the minikube cluster,

Assuming that you are into your local jenkins directory, type the following commands

$ minikube docker-env$ eval $(minikube -p minikube docker-env)

This will point your shell to dicker-daemon, run, as shown below

fig 3.0

Check that you are able to get all the pre-existing docker images in that docker-daemon env:(refer the fig 3.0, for command and output )

$ docker image ls 

Now that you have the docker -daemon running we can now go ahead and build the docker image by using the command shown below :

$ docker image build -t myjenkins .

Note!, the tag for the Jenkins image is myjenkins , which should match with the image tag mentioned in jenkins.yaml file (existing in your local directory), as shown below, and don't forget to apply the dot at the end with a single space while typing in your terminal, as this instructs the system to build the image from local Docker file.

4. Wait for the Jenkins Docker Image to build :

Mind it this process is quite heavy and may take some time, so be patient until you get the following message

  • “Successfully built “imageid(this will vary for you)” ”
  • “Successfully tagged myjenkins: latest”

As can be seen below in Fig 4.0

Fig 4.0

5. Deploy Jenkins Image :

Assuming that you are still in your local folder where jenkins.yaml file exist, if yes go ahead and type this k8s CLI command, to create a Jenkins deployment file using the jenkins docker image, we just created in the previous process

$ kubectl apply -f jenkins.yaml

6. Check If Jenkins image is deployed :

$ kubectl get all

You can see that,

  • pod: jenkins-79966d8db-x4kn7 is deployed and the jenkins
  • service(service/jenkins) is also up and running on the NodePort 30020
  • Deployment: deployment.apps/jenkins is also up and running on the NodePort: 31000

7. Running the Jenkins In Your Web :

If everything is set up. nicely without any error, you need to type the following command :

$ minikube ip

The above command gives the local IP of the minikube cluster, we will need this IP, to run the Jenkins UI and see it running in our web

$ minikube ip

As can be seen, for me my cluster IP is: 192.168.49.2

Open the web and type this URL given below :

192.168.49.2:31000, and you will see the following screen with a welcome message

What If Your URL is not working?

It may happen if you are using the docker driver while starting the minikube , instead of the virtual box. In this situation minikube IP will not functions and you will be required to start the local tunnel from your terminal using the following commands,

$ minikube service jenkins --url

The above commands start the tunnel for your jenkins service and give you the URL which needs to be used along with NodePort:53960 or 53961(this may vary in your case ), to access the Jenkins UI on your web browser

For me the URL will look like this:

“127.0.0.1:53960”, type this and now your Jenkins UI should work in the browser.

Congratulations!!!

Congratulation you have successfully configured the Jenkins on your local minikube cluster and now you are all set to, configure the Jenkins interface and start automating the code repository deployment without much fuss

What’s Next?

As the length of this piece is becoming big, in part 2 of this series, we will cover how to Configure multibranch repository and GitHub organization, using Jenkins UI interface and will see its magic to automate our CI/CD pipeline.

Part2 :

Signing Off Message:

“ When people within an organization, start collaborating with the intent to help each other the fabric for a stronger pipeline gets established which is bound to create success and happiness in the long run. DevOps is one such powerful tool to builds such a long-lasting culture ”

Thanks a ton for being with me and see you soon in the next part of CI/CD with Jenkins…

--

--

--

We share our knowledge regarding scalable architectures, clean coding, DevOps, CI/CD to help you learn and grow fast

Recommended from Medium

7 Benefits of SAP S/4 HANA on Cloud. Is your organization “Cloud- Ready”?

Docker With DevOps

Labex.io/alibaba

Mobile application: Which framework to choose for 2020?

5 practical tips on how to manage a corporate blog

Introduction to Objects in python

Scratch Engine

Coding Guidelines & Best Practice on PHP Programming Vol 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
@pramodAIML

@pramodAIML

Passionate Blogger & Tech Entrepreneur | Founder of FinTech Startup | Write about AIML, DevOps, Product Mgmt & Crypto

More from Medium

Load testing in DevOps practices

Java/web App deployment on kubernetes cluster.

Helm Chart: Release & Rollback

Helm Chart: Release & Rollback

Increased developer productivity with Kubernetes virtual cluster