π₯ Helm Chart to Deploy Jenkins in Kubernetes π₯
Hello Everyone πββοΈ
π₯ 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.
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
π 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.
π Create YAML file for exposing the services of Jenkins inside the templates folder.
π 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..
π 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
π₯ Pushing the charts in the GitHub repository
π Create a new repository in GitHub and upload charts folder into the GitHub repository.
π₯ 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.
Here, we got the URL
π₯ Publishing helm chart on artifact hub
π Go to artifacthub.io/
π 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
π₯³ π₯³ 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