How to Setup Jenkins on Kubernetes Cluster with Helm

bravinsimiyu

Bravin Wasike

Posted on June 2, 2023

How to Setup Jenkins on Kubernetes Cluster with Helm

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. Jenkins plugins can also be used to integrate with cloud providers such as Google Cloud, AWS, and Microsoft Azure. If you want to integrate any DevOps tool with Jenkins, you have to install its plugin in the Jenkins controller platform. You can check this article on Sweet Code about Jenkins.

In this tutorial, you will learn how to set up Jenkins CI/CD on Kubernetes Cluster using 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 using 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 Setup Jenkins CI/CD on Kubernetes Cluster using Helm

Helm is an open-source platform that was created by DeisLabs. Helm is used 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. Helms 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 Sweet Code 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 you can reuse other people's Helm charts. You can check this article on Sweet Code 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 complex applications like Jenkins, it is best to use the official Jenkins Helm Chart. Many Developers have contributed to the Jenkins Helm chart and it has all the Kubernetes YAML files. It will save us time in creating our custom Jenkins Helm chart. In this tutorial will search and download the official Jenkins Helm Chart from ArtifactHub. We 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. We will 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


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

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


Enter fullscreen mode Exit fullscreen mode

Windows

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



choco install kubernetes-helm


Enter fullscreen mode Exit fullscreen mode

macOs

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



brew install helm


Enter fullscreen mode Exit fullscreen mode

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

Image description

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



helm


Enter fullscreen mode Exit fullscreen mode

The command should output the following in your terminal:

Image description

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:

Image description

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



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


Enter fullscreen mode Exit fullscreen mode

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



helm repo update


Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode

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:

Image description

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


Enter fullscreen mode Exit fullscreen mode

Admin Password Output:

Image description

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


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

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:

Image description

You can then input your admin password and username to unlock the running Jenkins container instance.

Step Three: 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:

Image description

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:

Image description

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.

Image description

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:

Image description
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:

Image description

You can now 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:

Image description

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

Conclusion

In this tutorial, you have learned how to set up Jenkins CI/CD on Kubernetes Cluster using 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.

If you like this tutorial, let's connect on Twitter and LinkedIn for more insightful DevOps articles, tips and discussions.

💖 💪 🙅 🚩
bravinsimiyu
Bravin Wasike

Posted on June 2, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related