How to setup Jenkins On Kubernetes? A Step-By-Step Guide

The following are the effective steps for setting up Jenkins on Kubernetes:

Method 1: Install Jenkins with Helm v3

The following are the steps for the installation of Jenkins with Helm v3

Step 1: Download and install the Helm v3 from the Official Page

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Step 2: Add Jenkins Helm Repository

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

Step 3: Create Namespace for Jenkins with the following command:

kubectl create namespace jenkins

Step 4: Install Jenkins using Helm

helm install jenkins jenkins/jenkins --namespace jenkins

Step 5: Access Jenkins

  • Get the admin password with the following command:
printf $(kubectl get secret --namespace jenkins jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
  • Port forward to access the Jenkins UI:
kubectl --namespace jenkins port-forward svc/jenkins 8080:8080
  • Open http://localhost:8080 in your browser and log in with the admin password.

Method 2: Install Jenkins with YAML files

  • The following are steps using to Install the Jenkins with the Yaml Files

Step 1: Create a Namespace for Jenkins

 kubectl create namespace jenkins

Step 2: Create a Persistent Volume and Persistent Volume Claim

# pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi

Step 3: Create a Deployment and Service Yaml Files, The following are the sample yaml manifest files that we are using now:

# jenkins-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- containerPort: 8080
volumeMounts:
- name: jenkins-volume
mountPath: /var/jenkins_home
volumes:
- name: jenkins-volume
persistentVolumeClaim:
claimName: jenkins-pvc
---
apiVersion: v1
kind: Service
metadata:
name: jenkins
spec:
ports:
- port: 8080
targetPort: 8080
selector:
app: jenkins
  • Use the following command to apply the yaml manefist changes to the cluster:
kubectl apply -f jenkins-deployment.yaml -n jenkins

Step 4: Access Jenkins

  • Get the admin password with the following command:
kubectl exec --namespace jenkins -it $(kubectl get pods --namespace jenkins -l "app=jenkins" -o jsonpath="{.items[0].metadata.name}") -- cat /var/jenkins_home/secrets/initialAdminPassword 
  • Now, port forward to access the Jenkins UI with the following command:
kubectl --namespace jenkins port-forward svc/jenkins 8080:8080
  • Open http://localhost:8080 in your browser and log in with the admin password.

Method 3: Install Jenkins with Jenkins Operator

The following are the steps for the installation of Jenkins with Jenkins Operator:

Step 1: Clone the Jenkins operator repository

git clone https://github.com/jenkinsci/kubernetes-operator.git
cd kubernetes-operator
  • Apply the Custom Resource Definitions and the Jenkins Operator:
kubectl apply -f deploy/crds/
kubectl apply -f deploy/all-in-one-v1alpha2.yaml

Step 2: Create a Jenkins Custom Resource

# jenkins-cr.yaml
apiVersion: jenkins.io/v1alpha2
kind: Jenkins
metadata:
name: example
namespace: jenkins
spec:
master:
basePlugins:
- name: kubernetes
version: "1.29.7"
- name: workflow-aggregator
version: "2.6"
- name: git
version: "4.0.0"
containers:
- name: jenkins-master
image: jenkins/jenkins:lts
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /login
port: 8080
initialDelaySeconds: 80
periodSeconds: 10
  • Apply the jenkin-or.yaml manifest file to the cluster with the following command:
 kubectl apply -f jenkins-cr.yaml -n jenkins

Step 3: Access Jenkins

  • Get the admin password with the following command:
 kubectl get secret example-jenkins-operator-credentials-jenkins-admin-password -o jsonpath="{.data.password}" -n jenkins | base64 --decode
  • Port forward to access the jenkins UI with the following command:
kubectl --namespace jenkins port-forward svc/example-jenkins-operator-http 8080:8080
  • Open http://localhost:8080 in your browser and log in with the admin password.

kubernetes vs Jenkins

A popular automation server is Jenkins, while Kubernetes is an open-source framework for container orchestration. Selecting the best solution for your requirements might be difficult because Kubernetes and Jenkins both have special capabilities and advantages.

Table of Content

  • Difference Between Kubernetes and Jenkins
  • What Is Kubernetes?
  • Features Of Kubernetes
  • Benefits Of Kubernetes
  • Challenges Of Kubernetes
  • What Is Jenkins?
  • How to setup Jenkins On Kubernetes? A Step-By-Step Guide
  • Features Of Jenkins
  • Benefits Of Jenkins
  • Challenges Of Jenkins
  • Conclusion
  • Kubernetes And Jenkins – FAQ’s

Kubernetes is used by DevOps engineers, IT system administrators, and application developers to autonomously scale, deploy, maintain, plan, and run many application containers across node clusters. Jenkins simplifies continuous integration and continuous delivery by aiding in the automation of the building, testing, and deployment processes involved in software development. It is a server-based solution that is conducted in Apache Tomcat or other servlet containers.

Similar Reads

Difference Between Kubernetes and Jenkins

The following are the differences between Kubernetes and Jenkins:...

What Is Kubernetes?

Kubernetes, An open-source container orchestration platform makes software deployment, scalability, and administration automated. The Cloud Native Computing Foundation is the owner of the trademark, and a global network of volunteers now maintains the project that was initially established by Google....

Features Of Kubernetes

The following are the features of Kubernetes:...

Benefits Of Kubernetes

The following are the benefits of Kubernetes:...

Challenges Of Kubernetes

The following are the challenges of Kubernetes:...

What Is Jenkins?

Jenkins, An open-source automation server. It facilitates repeated integration and continuous delivery by aiding in the automation of the building, testing, and deployment processes involved in software development. It is a server-based solution that engage in Apache Tomcat or other servlet containers....

How to setup Jenkins On Kubernetes? A Step-By-Step Guide

The following are the effective steps for setting up Jenkins on Kubernetes:...

Features Of Jenkins

The following are the features of Jenkins:...

Benefits Of Jenkins

The following are the benefits of Jenkins:...

Challenges Of Jenkins

The following are the challenges of Jenkins:...

Conclusion

In this article we have learned about Kubernetes and Jenkins. Kubernetes is an open-source container orchestration platform composes software deployment, scalability, and administration automated and Jenkins is an open-source automation server preferred option for CI/CD processes....

Kubernetes And Jenkins – FAQ’s

Is Kubernetes better than Jenkins?...

Contact Us