Building CI/CD Pipeline with Jenkins, Kubernetes & GitHub: Part 2

How To Configure Jenkins To Build Your CI CD Pipeline?

@pramodchandrayan
SysopsMicro
7 min readMay 23, 2021

--

I feel:

“The world of microservices has lead to the DevOps innovation and this innovation is saving hell lot of time energy and money for the organization adopting it ”

This is in continuation to my first part :

DevOps CI/CD Pipeline with Jenkins, Kubernetes & GitHub

Now we will look deeper into how one can play with Jenkins powerful CI/CD features to automate the continuous integration and continuous deployment of the code repository existent in GitHub under the organization category

We will cover configuring:

  • Multibranch Pipeline
  • Github Organization pipeline

and see how the CI/CD pipeline is automatically executed with changes in the master branch.

Let’s get started with :

How To Configure the GitHub Credentials in Jenkins:

Before we go on to configure the multi-branch pipeline, we need to create some credentials in the Jenkins UI interface, why we need this is because our Jenkinsfile which will be a part of every repo in your organization, required these Credentials to fetch the code form your repo. These credentials

  • ORGANIZATION_NAME (This should be the name of your Github organization )
  • YOUR_DOCKERHUB_USERNAME(this can be dummy info ), because we are currently not taking the pull from any docker hub, in our sample demo. But for production, if you decide to your any docker container to deploy this created image, use the credentials of the same here can be seen in this below-given image of one of the Jenkinsfile scripts.

The steps required are as follows:

  • Go to the Manage Jenkins menu option
  • Click on Configure System
  • Click on Configure System and then go to the Global properties section under this, there you will have an option to create Environment variables
  • Fill ORGANIZATION_NAME & YOUR_DOCKERHUB_USERNAME, as discussed above, then go on to save the credentials
Fig 1.0: Welcome Jenkins page

Multibranch Pipeline Configuration:

In the first part of my Jenkins article, we saw how we can run the Jenkins UI in our web browser, now that you have got the Jenkins UI working as seen in Fig 1.0 above and also got the required environment variable configured, It’s time that we start configuring the multi-branch pipeline which will be triggering our CI/CD process for the given repo branch.

Here are the steps for the same:

  • Simply click on the “New Item “ menu tab,
Fig 2.0
  • Enter the repo name as “webapp” in the item name input box shown in the pic above, (you can keep whatever name that suits to your repo ), I have kept this because we are going to build CI/CD pipeline to deploy our fleetman-webapp repo as shown below
  • Then select Multibranch Pipeline Option and click the save option

You will then get a screen as shown above, where you need to fill,

  • Display name: “webapp” (you are free to choose your name), we can skip the description
  • Then go to the Branch Configuration section and click on Add source button, once you click the add button, you get a dropdown with some options to choose from, you have to pick Jenkins as we want Jenkins wide global credentials to be applicable across the organization repo.
  • Enter your GitHub username and password along with ID name
fig: Create Credentials
  • Please make sure ID name is “GitHub”, because as can be seen in our repo Jenkinsfile, the highlighted area below requires your git credentials, which will look for ‘GitHub ’ keyword to fetch the repo. But you are free to choose your name in Jenkinsfile and use the same in the Jenkins ‘ credentialsId’ config section.
  • Then you can save the credentials by clicking on add button as shown in the ‘fig: Create Credentials’ image above.

This will create the credentials against the Tag : GitHub, which has to be chosen from add source options as shown below, here you will get the drop-down with your GitHub username flashing, Once you are done selecting, you will be asked to enter,

  • Owner name: which should be the name of your organization, as soon you enter the Owner name, you will be able to view the list of repo’s attached with your Github organization. Select fleetman-web-app, repo, and save your configuration.

Magic Begins: Your Pipeline Will start building

Once you press the save button, magic will start, your CI/CD pipeline against the web app repo will start building, shown below

webapp Pipline Building

You will be able to locate the webapp pipeline building on the left PAN as shown in the fig above. You can click on the running pipeline and you will be redirected to the detail screen as shown below, where you will be able to view the pipeline being built with the pre-defined stages as mentioned in your Jenkinsfile configuration.

Congratulations: You are almost there

Your pipeline building will take some time, so you can relax or have some coffee in between. If your pipeline gets built successfully without any error, you will be able to see that every stage is shown in green

In my case, webapp pipeline has been successfully built and deployed in our Minikube K8s cluster,

Validate If deployment is Successful or Not:

Just check minikube status, to see if minikube is active or not.

If not active: Type the below-given command

Then type: kubectl get all , command as shown below

Output:

  • You can see from the highlighted area that, our webapp deployment is up and running.
  • Our service “fleetman-webapp” is also up and running on the NodePort 30080

Running the webapp deployment:

Get your local minikube cluster IP:

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

Open the web and type this URL given below , along with your fleetman-webapp NodePort number: 30080

“192.168.49.2:30080”, on your web browser

If everything goes fine you will be able to view the fleetman-webapp web page as shown below

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,

As can be seen from the above image, a tunnel service at port no : 60224 has been started, now you just need to go to your favorite browser and type

http://127.0.0.1:60224/ , and you should see the webapp , page opening as shown earlier.

Congratulations on getting your microservice deployed on your local minikube k8s cluster.

What’s Next?

We will look into one more powerful option available with Jenkins called “Github Organizations” which will allow you to pick all your master branch repo lying under your organization, in one go and trigger the CI/CD pipeline to build and deploy them in one go.

Meanwhile don’t forget to view part 1 of the Jenkins CI/CD auto-deployment series

And my other contributions related to Kubernetes:

and follow me for more informative articles on

  • Kubernetes
  • Crypto
  • DevOps and much more…

Note!

This sample repo has been forked from chesterwood and I am highly thankful to him for creating such an awesome CI/CD ready repository.

Thanks a ton for being there with me and inspiring me to write more and learn more…

--

--

@pramodchandrayan
SysopsMicro

Building @krishaq: an Agritech startup committed to revive farming, farmers and our ecology | Writes often about agriculture, climate change & technology