πŸ’₯ Helm Chart to Deploy Jenkins in Kubernetes πŸ’₯

Hello Everyone πŸ™‹β€β™€οΈ

Anuja Kumari
8 min readSep 25, 2021

πŸ’₯ In this article I’m explaining about Helm Chart, and How to Deploy Jenkins in Kubernetes using Helm Chart.

πŸ”° What is Kubernetes ?

πŸ‘‰πŸ» Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

πŸ”° What is Jenkins ?

πŸ‘‰ Jenkins is a free and open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.

πŸ”° What is Helm?

πŸ‘‰ Helm is a Kubernetes package and operations manager. The name β€œKubernetes” is derived from the Greek word for β€œpilot” or β€œhelmsman”, making Helm its steering wheel. Using a packaging manager, Charts, Helm allows us to package Kubernetes releases into a convenient zip (.tgz) file. A Helm chart can contain any number of Kubernetes objects, all of which are deployed as part of the chart. A Helm chart will usually contain at least a Deployment and a Service, but it can also contain an Ingress, Persistent Volume Claims, or any other Kubernetes object.

Helm charts are used to deploy an application, or one component of a larger application. It helps us to manage Kubernetes applications . Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.

πŸ”° What are Charts?

πŸ‘‰ Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources. A single chart might be used to deploy something simple, like a memcached pod, or something complex, like a full web app stack with HTTP servers, databases, caches, and so on.

Basic directory structure of the chart:

πŸ‘‰ These directory and file have their respective functions:

  • charts/: Chart dependencies can be placed in the directory.
  • templates/: This directory contains template files that are combined with configuration values and rendered into Kubernetes manifests.
  • Chart.yaml: This file consists the information about the chart, such as chart name and version, maintainer information, a relevant website, and search keywords.
  • LICENSE: A license for charts
  • README.md: A readme file with information for users of the chart.
  • values.yaml: This file stores the values that are used in the chart

Let’s begin 🀩

πŸ”… Creating a Dockerfile for deploying Jenkins

πŸ‘‰First create a separate workspace for a Dockerfile . I have created a directory named js-ws. In this workspace create a Dockerfile.

πŸ”… Build the Dockerfile by using below command

docker build -t <image_name>:<tag> /workspace

πŸ‘‰ Now, The image is ready to work in Kubernetes.

image

Let’s, Start with Helming🀩

πŸ”… Installing Helm

The URL where you can download helm according to your operating system. link .

πŸ‘‰ I am using Windows OS.

NOTE : Helm had the client-server architecture till version 2, We have to need to install a server-side program Tiller in the Kubernetes cluster. In version 3 helm provides more facilities i.e. install helm on the client-side only. It provides more security than version 2.

After downloading in windows extract the zip and go to folder, copy the path and add into the environment variable.

πŸ“Œ To check the helm installed or not :

helm version

πŸ”… Create Chart for Jenkins

πŸ‘‰ Create a new workspace or folder

create β€œChart.yaml” file inside that workspace

workspace
Chart.yaml

πŸ‘‰ Now create one more folder inside the workspace β€œjenkins” Folder name will β€œtemplates”

Create a YAML file for launching the deployment for Jenkins inside the templates folder.

deployment.yaml

πŸ‘‰ Create YAML file for exposing the services of Jenkins inside the templates folder.

service.yaml

πŸ‘‰ Now we will install the chart as we create earlier using helm.

helm install <chart_name> folder_name/

Now, our Jenkins deployment and service has been install also.

πŸ‘‰ To check run the below commands:

kubectl get deploy
kubectl get pods
kubectl get svc

πŸ‘‰ After running the command pick the port number that has been exposed jenkins service. And If you run a single node cluster minikube, run below command to check ip.

minikube ip

Note: This command will give ip of your minikube enter it in the below URL

πŸ‘‰ Now type http://<minikube ip>:<port_no> in browser.

A page will appear asking for an administrator password .

πŸ‘‰ Let’s use kubectl to pull the password from those logs.

kubectl logs <pod_name>

πŸ‘‰ The selected text is the initial password to login to Jenkins πŸ‘†

Copy the password and paste into Jenkins UI.

πŸ‘‰ Click on continue….

Now, our jenkins setup is ready πŸ˜„

πŸ‘‰ Let’s run a Sample Job…..

Click on New item..

πŸ‘‰ Enter an item name and select Freestyle project

πŸ‘‰ Select Execute shell, and write any command of Linux in the box(Here, i am giving cal command) then click onSave button.

πŸ‘‰ Click on build now..

console output

πŸ”… Publish Helm Chart on Artifacthub.io

Artifact hub is a web-based application that helps to storing and installing helm packages. It is a public repository everyone can contribute to it by creating and publishing charts for any technologies.

πŸ’₯ Creating a package of the chart

πŸ‘‰ Create a directory(named -> charts) where we will store everything related to our chart and also this folder will go to artifacthub.io/ .

mkdir charts

Artifact hub only allows archive files so the package will provide an archive file of the chart.

πŸ‘‰ Run the following command to create the package

$ helm package jenkins -d charts       

In the above command jenkins is the chart name and charts is the directory name.

πŸ‘‰ Go to charts directory and run the following command, here we can see tar file

πŸ’₯ Creating an index.yaml file

We have to need to create an index.yaml file for every chart. It contains all the information or metadata of our chart.

πŸ‘‰ Now, run the following command to create index.yaml

helm repo index charts
index.yaml

πŸ’₯ Pushing the charts in the GitHub repository

πŸ‘‰ Create a new repository in GitHub and upload charts folder into the GitHub repository.

GitHub repo

πŸ’₯ Hosting Chart using GitHub Pages

We require a URL where we had hosted our helm chart for publishing the Helm chart on artifacthub.io/. So, host our charts using GitHub pages.

πŸ‘‰ Go to the settings of your GitHub repository and go to the GitHub Pages section.

πŸ‘‰ Select master as a branch and click on save.

GitHub Pages

Here, we got the URL

πŸ’₯ Publishing helm chart on artifact hub

πŸ‘‰ Go to artifacthub.io/

Artifact Hub

πŸ‘‰ Click on your profile then Click on the Control plane πŸ‘†

πŸ‘‰ Click on Add repository πŸ‘†

πŸ‘‰ Select the kind as Helm charts, provide a name to the repository and enter the URL provided by the GitHub pages

πŸ‘‰ Click add, It will publish the chart

Repository

πŸ₯³ πŸ₯³ Successfully published the helm chart on artifact hub.

πŸ“ŒArtifact link : https://artifacthub.io/packages/helm/helm-chart-to-deploy-jenkins/jenkins

πŸ“Œ GitHub link : https://github.com/Anujakumari/Jenkins-Helm-Chart

I hope my article will be helpful for you all 🀩

Happy Helming πŸ˜ƒπŸ˜ƒ

!! Keep learning !! keep sharing 🧾

🀩 Feel free to connect with me 🀩

πŸ‘‰ LinkedIn : https://www.linkedin.com/in/anuja-kumari-4a62581aa

πŸ‘‰ GitHub : https://github.com/Anujakumari

--

--

Anuja Kumari

Learner @ Linuxworld Informative Pvt Ltd || DevOps(Docker,K8S, Jenkins, Terraform, Git and GitHub) || AWS || ( Python | Java )