How to Setup Jenkins CI/CD Pipeline on Kubernetes Cluster with Helm

2712 VIEWS

·

Jenkins is an open-source multi-platform software for continuous integration/continuous delivery and deployment (CI/CD) in DevOps. It is one of the most common CI/CD tools. Jenkins uses CI/CD pipelines to automate the software development and deployment workflows. 

Jenkins uses plugins to integrate with DevOps tools such as Docker and Kubernetes. Its plugins can integrate with cloud providers such as Google Cloud, AWS, and Microsoft Azure. You can check this article on Sweet Code to learn more about Jenkins.

This tutorial will teach you how to set up Jenkins CI/CD on Kubernetes Cluster with Helm. Helm is one of the easiest ways of installing an application on the Kubernetes Cluster.

Prerequisites

For you to follow this tutorial on how to Setup Jenkins CI/CD on Kubernetes Cluster with Helm, you must:

  • Have Docker set up and understand how to use Docker: You can check out this article on Sweet Code to set up and understand Docker.
  • Understand Kubernetes. You can check out this article on Sweet Code to understand Kubernetes.

How to Set Up Jenkins CI/CD on Kubernetes Cluster with Helm

Helm is an open-source platform that DeisLabs created. It uses Helm as the package manager for Kubernetes. Many developers use Helm to install any Kubernetes application to the Kubernetes Cluster. Helm automates the process of deploying a Kubernetes application to the Kubernetes Cluster. It bundles a Kubernetes application into a single package known as a Helm chart. 

Developers will then take this Helm chart and install them on the Kubernetes Cluster. You can check this article on Sweetcode about deploying Helm Chart to Kubernetes.

A Helm chart contains all the Kubernetes YAML files for deploying a Kubernetes application. Once you install the Helm chart on the Kubernetes Cluster, it will create the Kubernetes components such as Kubernetes Deployment and Service on the Kubernetes cluster. You can create your Helm chart using Helm or reuse other people’s Helm charts. You can check this article on Sweetcode to learn more about Helm and Helm Charts.

Helm has an official Helm Chart repository called ArtifactHub where developers can push and publish their Helm Charts. In this repository, you can easily find Helm charts for any Kubernetes application and reuse them. For a complex application like Jenkins, it is best to use the official Jenkins Helm Chart. Many Developers have contributed to the Jenkins Helm chart, which has all the Kubernetes YAML files. 

It will save you time in creating your custom Jenkins Helm chart. In this tutorial you will search and download the official Jenkins Helm Chart from ArtifactHub. You will then install the official Jenkins Helm Chart on the Kubernetes Cluster using Helm. Let’s install Helm.

Installing Helm

Before you install Helm, you must configure/create a Kubernetes Cluster. You will then install Helm on the configured Kubernetes Cluster. There are various Kubernetes Kubernetes Clusters that you can configure. Cloud providers like Google Cloud, AWS, and Microsoft Azure have a dedicated Kubernetes Cluster that you can configure and use. 

In this tutorial, we will not use any of the cloud providers. Instead, we will use a local Kubernetes called Minikube that comes with Docker. As long as you have Docker running, you can easily configure Minikube. To configure and start Minikube, follow these steps:

Step One: Start Docker

Once you have started Docker, it is now easy to start Minikube.

Step Two: Configure and start Minikube

To configure and start Minikube Minikube, run this command in your shell:

minikube start

Output:

Now that we have configured and started our Kubernetes Cluster (Minikube), let’s install Helm. There are different ways of installing Minikube on your specific operating system. I will show you how to install Helm on Linux, macOS, and Windows.

Linux

For Linux, you can run this command in your shell:

sudo apt-get install helm
Windows

For Windows, you can run this command in your shell:

choco install kubernetes-helm
macOS

For macOS, you can run this command in your shell:

brew install helm

I have installed Helm on my Windows operating system, as shown below:

To check if Helm is running in your Kubernetes cluster, run this in your shell:

helm

The command should output the following in your terminal:

After you have installed Helm on your specific operating system, the next step is to search for the official Jenkins Helm Chart on the ArtifactHub.

Searching for the Official Jenkins Helm Chart

You can click on this link to open ArtifactHub. You can then search for Jenkins as shown below:

To use the official Jenkins Helm Chart, run this command in your shell:

helm repo add jenkins https://charts.jenkins.io

It will download and add the official Jenkins Helm Chart repository. To update this repository, run this command in your shell:

helm repo update

Installing the Official Jenkins Helm Chart on the Kubernetes Cluster Using Helm

To install the official Jenkins Helm Chart on the Kubernetes Cluster using Helm, run this command in your shell:

helm install myjenkins jenkins/jenkins

This command will deploy the Jenkins CI/CD on the Kubernetes cluster. Helm will use the Kubernetes YAML files in the Helm and create the Kubernetes components (Deployment and Service). We have reused the official Jenkins Helm Chart to set up the Jenkins CI/CD on the Kubernetes Cluster. 

Output:

To start using the Jenkins CI/CD running on the Kubernetes Cluster, follow these steps:

Step One: Get your ‘admin’ password for Unlocking Jenkins

To get the admin password, run this command in your shell:

kubectl exec --namespace default -it svc/myjenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password && echo

Admin Password Output:

Step Two: Get the Jenkins URL

To get the Jenkins URL, run the following shell command:

kubectl --namespace default port-forward svc/myjenkins 8080:8080

Output:

This command will expose the Jenkins container instance on port 8080. You can go to http://127.0.0.1:8080 to access the Jenkins CI/CD 

Step Three: Login into Jenkins with Admin Password and Username

To login into Jenkins with an admin password and username, open http://127.0.0.1:8080 in your browser to access your running Jenkins container instance:

Then, you can input your admin password and username to unlock the running Jenkins container instance.

Step Four: Finishing setting up Jenkins CI/CD 

To finish setting up Jenkins CI/CD, follow these steps:

Step One: Customize Jenkins

You will install the suggested plugins to customize Jenkins:

After a few minutes (depending on your internet speed), it will install the suggested plugins. Jenkins will use the plugins to integrate with other software:

Step Two: Creating First Jenkins Admin User

You need to create a first Jenkins Admin user who will have control over the Jenkins platform. The Admin user will perform all actions/tasks in the Jenkins platform, like starting CI/CD pipelines and managing Jenkins.

You can input all the admin user details and then click the ‘Save and Continue’ button. 

Step Three: Adding Jenkins URL

You can add the Jenkins URL as shown below:

You can click ‘Save and Finish’ and Jenkins will be ready.

Start Using Jenkins

To start using Jenkins, click on the ‘Start using Jenkins’ button:

Now you can start using Jenkins to create all your Jenkins CI/CD pipeline for automating the software development and deployment workflows. You will have access to the Jenkins Dashboard as shown below:

You have successfully set up Jenkins CI/CD on Kubernetes with Helm and can access the Jenkins Dashboard.

Conclusion

This tutorial taught you how to set up Jenkins CI/CD on Kubernetes Cluster with Helm. We used Helm because it’s one of the easiest ways of installing an application on the Kubernetes Cluster. This tutorial shows you how to install Helm on Linux, macOS, and Windows. It also shows you how to search for the Official Jenkins Helm Chart. We also installed the official Jenkins Helm Chart on the Kubernetes Cluster using Helm.

Additionally, this tutorial shows you how to get your ‘admin’ password for unlocking Jenkins and how to login into Jenkins. In the end, we finished setting up Jenkins CI/CD on Kubernetes using Helm and accessed the Jenkins Dashboard. Hope this tutorial helps you in getting started with Jenkins.


Lewel is a DevOs engineer with a Bachelor's Degree in Computer Science. He is passionate about creating DevOps infrastructure using Terraform and deploying containerized applications to Kubernetes. He has experience with Jenkins CI/CD, Azure DevOps and cloud based Kubernetes Services. He hopes his DevOps skills will help in automating software development and deployment.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu
Skip to toolbar