Or copy link
Copy link
Kubernetes provides an automation platform that can manage Jenkins instances, ensuring high availability and fault tolerance. By exploring Kubernetes, Jenkins can dynamically scale to handle varying workloads, optimize resource utilization, and facilitate seamless updates and rollbacks. This integration enhances the efficiency and reliability of the CI/CD process, enabling development teams to deliver software faster and with greater confidence.
In this tutorial, we will demonstrate the step-by-step instructions to install and configure Jenkins on Kubernetes.
Installing Jenkins on Kubernetes offers a scalable and resilient solution for continuous integration and continuous delivery (CI/CD) pipelines. For installing Jenkins on Kubernetes, consider the below steps:
Before starting the guide, make sure that you meet the following prerequisites:
If you meet the prerequisites, you are good to go with the installation process.
Install Jenkins on Kubernetes With our NVMe VPS!
Streamline your CI/CD with Jenkins on Kubernetes using UltaHost. Enjoy seamless scalability, blazing-fast speeds, and unmatched uptime for reliable deployments.
First, create a namespace for Jenkins to keep its resources isolated from other applications:
sudo kubectl create namespace jenkins
Utilize the below command to list existing namespaces:
sudo kubectl get namespaces
The result shows that the jenkins namespace is successfully created:
In this step, users can create a service account with Jenkins-specific permissions. The below file defines a cluster role with administrative privileges. It creates a new service account called admin and links it to the previously established cluster role.
Let’s create a file called sa-jenkins.yaml and add the following content:
sudo nano sa-jenkins.yaml
Copy and paste the below lines in the sa-jenkins.yaml file:
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: admin rules: - apiGroups: [""] resources: ["*"] verbs: ["*"] apiVersion: v1 kind: ServiceAccount metadata: name: admin namespace: jenkins apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: admin subjects: - kind: ServiceAccount name: admin namespace: jenkins
After that, apply the configuration by executing the following command:
sudo kubectl apply -f sa-jenkins.yaml
Read also How to Deploy Kafka on Kubernetes
Now, creating a persistent volume as well as persistent volume claim for Jenkins data. A persistent volume stores main Jenkins data beyond the lifetime of a pod. Follow the steps below to generate a YAML file that defines the storage-related components of the deployment.
Let’s create a file named volume-jenkins.yaml with the following command:
sudo nano volume-jenkins.yaml
Now add the following content in the newly created file:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: local-storage provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer --- apiVersion: v1 kind: PersistentVolume metadata: name: jenkins-pv labels: type: local spec: storageClassName: local-storage claimRef: name: jenkins-pvc namespace: jenkins capacity: storage: 10Gi accessModes: - ReadWriteOnce local: path: /mnt nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - minikube --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: jenkins-pvc namespace: jenkins spec: storageClassName: local-storage accessModes: - ReadWriteOnce resources: requests: storage: 3Gi
The first section of the file defines the local-storage storage class. The second section addresses the Jenkins-pv persistent volume, and the third builds a persistent volume claim called jenkins-pvc that binds to the Jenkins-pv volume.
In the nodeAffinity section, the values contain the name of the node that jenkins will utilize. In the above, minikube is used, hence the node’s name is minikube:
After that, apply the configuration with the following command:
sudo kubectl apply -f volume-jenkins.yaml
In this step, create a deployment for Jenkins. A deployment object manages scalability and pod updates, as well as the number of pods that are deployed. Now, create a Jenkins deployment by following the instructions below:
Let’s create a file called deploy-jenkins.yaml and include the following content:
sudo nano deploy-jenkins.yaml
Paste the below script in the created file:
apiVersion: apps/v1 kind: Deployment metadata: name: jenkins namespace: jenkins spec: replicas: 1 selector: matchLabels: app: jenkins-server template: metadata: labels: app: jenkins-server spec: securityContext: fsGroup: 1000 runAsUser: 1000 serviceAccountName: admin containers: - name: jenkins image: jenkins/jenkins:lts resources: limits: memory: "2Gi" cpu: "1000m" requests: memory: "500Mi" cpu: "500m" ports: - name: httpport containerPort: 8080 - name: jnlpport containerPort: 50000 livenessProbe: httpGet: path: "/login" port: 8080 initialDelaySeconds: 90 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 5 readinessProbe: httpGet: path: "/login" port: 8080 initialDelaySeconds: 60 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 3 volumeMounts: - name: jenkins-data mountPath: /var/jenkins_home volumes: - name: jenkins-data persistentVolumeClaim: claimName: jenkins-pvc
The deployment file in this scenario uses the jenkins/jenkins:lts Docker image to generate a single replica that will be exposed on port 8080.
The volumeMounts portion of the file mounts the persistent volume established in the preceding step. The livenessProbe and readinessProbe sections define probes for restarting failed pods and determining when pods are ready:
Now, apply the configuration:
sudo kubectl apply -f deploy-jenkins.yaml
Create a service to expose Jenkins. A Kubernetes service is an abstraction that connects Jenkins to the larger network. It enables the user to retain a persistent connection to the pod independent of changes in the cluster.
Let us create a file called service-jenkins.yaml and insert the below content:
sudo nano service-jenkins.yaml
Now, insert the below code to the file:
apiVersion: v1 kind: Service metadata: name: jenkins-svc namespace: jenkins annotations: prometheus.io/scrape: 'true' prometheus.io/path: / prometheus.io/port: '8080' spec: selector: app: jenkins-server type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 32000
Apply the configuration by executing the following command:
sudo kubectl apply -f service-jenkins.yaml
Jenkins on Kubernetes is managed by the Jenkins Operator, a native Kubernetes software extension. You can use the below-given kubectl commands to install it:
sudo kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/config/crd/bases/jenkins.io_jenkins.yaml
After that, install the Jenkins operator through the YAML files as below:
sudo kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/all-in-one-v1alpha2.yaml
To see the operator become ready, add the -w option to the kubectl get command as shown below:
sudo kubectl get pods -w
If you find any connection-relevant error, execute the “minikube start –force” command.
When you initially access Jenkins, you will be requested to enter an initial admin password. The output’s status portion contains the node IP address:
sudo kubect get nodes -o yaml
Once Jenkins is deployed and the service is created, users can easily access Jenkins through the NodePort. Open your browser and navigate to http://<NodeIP>:32000:
Look for the pod’s Name in the output of the following command to obtain the password:
sudo kubectl get pods -n jenkins
Now, retrieve the password from the Jenkins pod:
sudo kubectl logs [pod_name] --namespace jenkins
Locate the password, which is a lengthy alphanumerical string, at the end of the log:
Users can copy the given password and put it into the Jenkins unlock window:
After you unlock Jenkins, you will be prompted to install suggested plugins. Here, pick the Select plugins to install to start option:
Follow the on-screen instructions to complete the installation. The left side of the page displays a list of plugins arranged by category. Pick the plugins to use and click the Install button:
Now, create an admin user to manage Jenkins. After entering the required information in the user creation form, click Save and Continue button:
Once the setup is complete, you can start configuring Jenkins according to your needs:
You have successfully installed Jenkins on Kubernetes. Users can now start creating as well as managing CI/CD pipelines.
Installing Jenkins on Kubernetes is essential for achieving a robust and scalable CI/CD pipeline. Kubernetes provides an automation platform that ensures high availability, fault tolerance, and efficient resource management for Jenkins instances. This setup allows Jenkins to handle varying workloads dynamically, optimize resource utilization, and facilitate seamless updates and rollbacks. By searching Kubernetes, development teams can enhance the reliability and efficiency of their CI/CD processes, ultimately accelerating software delivery and improving overall productivity.
We hope this guide has helped you install Jenkins on Kubernetes. Consider Ultahost’s Linux VPS hosting which provides maximum flexibility and control. Ultahost handles all administrative tasks to ensure your servers operate smoothly, efficiently, and with reliable uptime. Buy VPS now and take your online presence to the next level!
Installing Jenkins on Kubernetes offers a scalable and resilient solution for CI/CD pipelines, ensuring high availability, fault tolerance, and efficient resource management.
Use the command kubectl to create namespace jenkins to create a namespace for Jenkins, keeping its resources isolated from other applications.
A service account with the necessary permissions is required for Jenkins to interact with the Kubernetes cluster securely.
Create a file named jenkins-pv.yaml with the necessary configuration and apply it using the command kubectl apply -f volume-jenkins.yaml.
Create a service file named jenkins-service.yaml and apply it using the command kubectl apply -f service-jenkins.yaml to expose Jenkins.
Create a deployment file named jenkins-deployment.yaml with the required configuration and apply it using the command kubectl apply -f deploy-jenkins.yaml.
The Jenkins Operator is a native Kubernetes software extension that manages Jenkins on Kubernetes. Install it using the commands provided in the tutorial.
Kubernetes, a powerful container orchestration platform...
Jenkins is an open-source automation server widely used...
Kubernetes is an open-source container orchestration sy...
Kubernetes, a popular container orchestration platform ...
Jenkins is a powerful open-source automation server tha...
Apache Kafka is a distributed streaming platform that e...
Save my name, email, and website in this browser for the next time I comment.
Δ