Open In App

Setup Jenkins On Kubernetes Cluster

Last Updated : 27 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Setting up Jenkins on a Kubernetes cluster involves deploying Jenkins as a containerized application within the cluster. Kubernetes is Born in Google, written in Go/Golang. Donated to CNCF(Cloud native computing foundation) in 2014. Kubernetes v1.0 was released on July 21, 2015. Current stable release v1.29

What Is Kubernetes?

Kubernetes is an orchestration engine and open-source platform for managing containerized applications. which is responsible for container deployment, scaling & descaling of containers v& container load balancing.Kubernetes is not a replacement for Docker, But Kubernetes can be considered as a replacement for Docker Swarm, Kubernetes is significantly more.

What Is Kubernetes Service?

In Kubernetes, each pod is assigned its own IP address but the pods are ephemeral that is they can be destroyed easily and when a new pod is created in place of them a new IP address is assigned to them. Here the role of services comes into the picture. A service is like a permanent IP address assigned to a pod. A service IP address is stable. So instead of sending a request to a pod, the client makes a request to a service, and the service forwards that request to the desired pod. Services also help in load-balancing.

Read – Kubernetes – Service

Types Of Kubernetes Service

There are four types of services available in Kubernetes.

  • ClusterIP
  • NodePort
  • LoadBalancer
  • Headless

Step-by-Step Guide To Setup Jenkins On K8’s Cluster

1. Creating NameSpace For Jenkins

Step 1: Login into your Kubernetes cluster here I was using an online platform for Kubernetes which is KillerCORDA. Which will give you the pre-configured Kubernetes environment.

Step 2: Create a Kubernetes namespace in the Kubernetes cluster in which you can deploy your Jenkins pod. Here I was naming my namespace as a test-ns as shown below.

apiVersion: v1
kind: Namespace
metadata:
name: test-ns
labels:
team: testingteam

This namespace can’t be accessed by any others who are not having access to the namespace.

2. Creating YAML file Jenkins

Step 3: Create a new file to write a YAML file for Jenkins as shown in the image below

vi <name of the file>

VI jenkins

Step 4: Write the yam file for the jenkins in that file . You can use the following yam file to create jenkins pod.

apiVersion: v1
kind: Pod
metadata:
name: jenkinsapp
namespace: test-ns
labels:
app: jenkinsapp
spec:
containers:
- name: jenkins
image: jenkins/jenkins:latest # Corrected image tag
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: jenkinsappsvc
namespace: test-ns
spec:
type: NodePort
selector:
app: jenkinsapp
ports:
- port: 80
targetPort: 8080

Here we are using nodeport service whih is used to expose the application in the kubernetes pod to the internet.

Jenkins yaml file

3. Applying the yaml file to create jenkins pod

Step 5: know save the file and apply the yaml for that kubectl command can be used.

kubectl apply -f <<name of the file>

Screenshot-(569)

Pod and the service was create sucessfully you can even create service in the different file which is best practice. Here we have created both at single place.

4. Testing the Jenkins Pods Status

Step 6: To know the pod is running perfectly and the port of the service which we need to aceses can by get the pods in that name space.

kubectl get all -n test-ns (kubectl get all -n <Replace with  your namespace>)

Here you will get all the services and the pods which are running in the test-ns namespce which is create in the step 1.

Screenshot-(572)-(1)

In the above image you can see the pod name jenkinsapp was ready and running sucessfully and the service type if Nodeport and port was 32761 which we need to use while acessing from the internet.

Step 7: Use your node ip adress and the port assigned in the k8s cluster to acesess the jenkins form the internet the URL will be as follows.

http://<Node-IP>:32761

If the k8’s was setup in the minikube then it will be,

http://<minikube-ip>:32761

Setup Jenkins On Kubernetes Cluster – FAQ’s

What Is Jenkins X?

Jenkins X is used to initiate a cluster creation in seconds with a single command. No more manual configuration or complex setups.

What is Helm In Kubernetes?

HELM is an open-source package manager for Kubernates, a powerful container orchestration platform for modern applications. It is officially owned by Kubernetes and managed by the Cloud Native Computing Foundation (CNCF).



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads