Deploy Jenkins in the Kubernetes cluster

Deploying Jenkins on a Kubernetes cluster can be quite beneficial for managing CI/CD pipelines efficiently. Here's a general guide to get you started:

Prerequisites:

  • You should have a running Kubernetes cluster.

  • kubectl should be configured to connect to your cluster.

Check kubernetes cluster and nodes

kubectl get nodes

Create the Jenkins directory and navigate the directory

mkdir jenkins

cd jenkins

Create a YAML file called jenkins-deployment.yaml with the following content

vi 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:
        - name: http-port
          containerPort: 8080
        - name: jnlp-port
          containerPort: 50000
        volumeMounts:
        - name: jenkins-vol
          mountPath: /var/jenkins_home
      volumes:
      - name: jenkins-vol
        emptyDir: {}

Expose the Jenkins deployment using a NodePort service:

vi jenkins-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: jenkins
spec:
  selector:
    app: jenkins
  ports:
  - name: http-port
    port: 8080
    targetPort: 8080
    nodePort: 30000
  type: NodePort

Apply the YAML file to create the Jenkins service:

kubectl apply -f jenkins-deployment.yaml

kubectl apply -f jenkins-service.yaml

Check the service's

kubectl get all

To verify if the Jenkins service is running from your terminal, execute the following command:

Access Jenkins:

Access Jenkins using the external IP and NodePort:

Navigate to the NeevCloud panel > Server > Select you node > copy Public_IP

Check Node Port

http://Node_IP: Nodeport

Last updated