Breaking

Setup Jenkins on Kubernetes

Introduction

This guide will walk you through the process of setting up Jenkins in Kubernetes. Jenkins is one of the tools used for continuous integration and continuous deployment (CI/CD) widely adopted by DevOps for continuous deployment. You will then access the Jenkins UI and run a sample pipeline.


Setup jenkins on kubernetes

Prerequisites:

Kubernetes cluster and pre-prepared kubectl. Follow the Kubernetes setup guide.

Step 1 – Installing Jenkins on Kubernetes

First, create a namespace :



Next, create a volume file for Jenkins named volume-jenkins.yaml. Here, I'm using the nfs storage class. You can follow the dynamic provisioning guide for nfs to use the default nfs storage for Kubernetes deployment.

Create a YAML file for Jenkins volume:

volume.yaml


Now, create the Jenkins volume using kubectl:

kubectl apply -f volume.yaml

Next, create a ServiceAccount with the file ServiceAccount.yaml:


Create a ServcisAcount.yaml file for jenkins-admin clusterRole and Service Account to bind Jenkins services. The ServcisAccount.yaml file grants jenkins-admin cluster role permission to manage cluster components.

Now, create a service acount for Jenkins using kubectl:

kubectl apply -f  ServcisAccount.yaml

Create a deployment-jenkins.yaml file; here, I am using the latest Jenkins image from the Docker Hub.



Now, create a deployment for Jenkins using kubectl:

kubectl apply -f  deployment-jenkins.yaml

Create a service.yaml file for the Jenkins service.


Now, create a service for Jenkins using kubectl:

kubectl apply -f  service.yaml

To ensure that the Jenkins pods and deployment are running in Kubernetes, you can use the following commands:


To view the default Jenkins password, you can use the following kubectl command:

kubectl logs deployment.apps/jenkins -n devops-tools

Related article :

To view the default Jenkins password, use:

default pasword admin jenkins


Since NodePort is used for the Jenkins service, access the Jenkins dashboard using the nodeport services URL:

Since NodePort is used for the Jenkins service, access the Jenkins dashboard using the nodeport


URL: https://ip-node-k8s:PortNodePort
Example: https://10.20.30.40:32000

Enter the default Jenkins password from the Jenkins deployment logs.

use password default admin jenkins

Wait for the Jenkins plugin installation steps to complete.

Jenkins plugin installation steps to complete.

Select "Skip for now."

Select "Skip for now."

Enter the Jenkins URL into your Jenkins server address. Select "Save and Finish."

finish install jenkins

Congratulations, you have successfully set up Jenkins deployment on Kubernetes.


Conclusion

In this article, we have explored how to configure Jenkins in Kubernetes and set up Jenkins deployment on Kubernetes. When using Jenkins for CI/CD in a project, it requires plugins such as GitLab or Kubernetes to connect to GitLab or Kubernetes.


Next, refer to the comprehensive guide for Jenkins CI/CD to automate deployments and best practices using a step-by-step guide.

No comments:

Post a Comment