# Deploy Jenkins in the Kubernetes cluster

## 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
```

<figure><img src="/files/OKjaNorWuVaD6286v8zy" alt=""><figcaption></figcaption></figure>

## Setup Jenkins deployment

### Create the Jenkins directory and navigate the directory

```
mkdir jenkins
cd jenkins
```

<figure><img src="/files/lelqDLH375WReIiyuKqv" alt=""><figcaption></figcaption></figure>

### Create a Jenkins deployment YAML file

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: {}
```

### Create a Jenkins service YAML file

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
```

<figure><img src="/files/Vb1wHxRCXeICBoQ6gDEi" alt=""><figcaption></figcaption></figure>

### Apply the YAML file to create the Jenkins service:

```
kubectl apply -f jenkins-deployment.yaml 
```

```
kubectl apply -f jenkins-service.yaml
```

<figure><img src="/files/ysxUK1kwQo50fLmJebFf" alt=""><figcaption></figcaption></figure>

Check the service's&#x20;

```
kubectl get all
```

<figure><img src="/files/mCaAq3TquWQXcIg9Dmg3" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/P9T00X633Basso3Kd6S4" alt=""><figcaption></figcaption></figure>

### **Access Jenkins:**

Access Jenkins using the external IP and NodePort:

**Navigate to the NeevCloud panel > Server > Select your node > copy Public\_IP**&#x20;

<figure><img src="/files/pPZxVHasL9nm3UG98buH" alt=""><figcaption></figcaption></figure>

Check Node Port

<figure><img src="/files/RW0NNcwaLOfWa7rARoa8" alt=""><figcaption></figcaption></figure>

**<http://Node\\_IP>: Nodeport**

<figure><img src="/files/dp7qPfb30Vc7DhFDFSzT" alt=""><figcaption></figcaption></figure>

Run this path on your terminal using the sudo (root user)

<figure><img src="/files/h4hpUxRqowbxK1nNxozW" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neevcloud.com/neevcloud-guide/kubernetes/deploy-jenkins-in-the-kubernetes-cluster.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
