# Project 15: Jenkins Driven: CI/CD for Uber Clone (Step By Step Implementation)

### **Introduction:**

Welcome to "Jenkins Driven: CI/CD for Uber Clone" – an immersive journey into the heart of DevSecOps automation. 🚀 In this project, we leverage the power of Jenkins to orchestrate a robust CI/CD pipeline for deploying an Uber clone app. From setting up AWS resources and Terraform provisioning to integrating SonarQube for security scans, Docker for containerization, and Kubernetes for seamless deployment – this guide is your compass through the intricate landscape of modern software development. 🌐 Fasten your seatbelts as we navigate the cloud-native realm, ensuring a smooth ride from code to production. Let's embark on this Jenkins-driven adventure in building and securing your Uber-inspired application! 🛠️💻

### **Technologies Used in This Project:**

1. **Jenkins:** 🚀 As the heart of the CI/CD pipeline, Jenkins orchestrates the seamless integration and deployment of the Uber Clone app, ensuring efficiency and automation in the software development lifecycle.
    
2. **Terraform:** ☁️ Leveraging Terraform, we automate the provisioning of AWS resources and the creation of an Elastic Kubernetes Service (EKS) cluster, enabling scalable and efficient infrastructure management.
    
3. **SonarQube:** 🔍 SonarQube enhances code quality by providing continuous inspection and reporting. It identifies and fixes security vulnerabilities and ensures adherence to coding standards in our Uber Clone application.
    
4. **Docker:** 🐳 Docker facilitates containerization, enabling the consistent deployment of the Uber Clone app across different environments. It enhances scalability, portability, and resource efficiency.
    
5. **Kubernetes:** 🚢 Kubernetes orchestrates the deployment, scaling, and management of containerized applications. In our project, it ensures the efficient running of the Uber Clone app, enhancing scalability and reliability.
    
6. **Node.js:** 🌐 Node.js powers the backend of our Uber Clone app, providing a scalable and high-performance runtime environment for building server-side applications.
    
7. **OWASP Dependency-Check:** 🛡️ This tool scans project dependencies for known vulnerabilities, ensuring that our Uber Clone app is protected against potential security threats.
    
8. **Trivy:** 🕵️‍♂️ Trivy performs container image vulnerability scanning, allowing us to identify and mitigate security risks in the Docker images used in our project.
    
9. **GitHub:** 🛂 GitHub serves as the version control and collaboration platform, enabling effective team collaboration, version tracking, and code review for the Uber Clone project.
    
10. **Elastic Kubernetes Service (EKS):** 🌐 Amazon EKS simplifies the deployment, management, and scaling of containerized applications using Kubernetes, enhancing the scalability and availability of our Uber Clone app.
    

### **Project Overview:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704130700244/3ad6cef6-74bd-44f3-af72-8c6fa817338a.png align="center")

### **Project:**

GITHUB REPO: [https://github.com/patelajay745/uber-clone.git](https://github.com/patelajay745/uber-clone.git)

`Step 1 : Launch Ec2 Instance` with Ubnuntu AMI and t2.large type. I have used following terraform file to launch it.

```bash
provider "aws" {
  region = "us-east-2" # Change this to your desired AWS region
}

resource "aws_instance" "my_instance" {
  count = 1


  ami                    = "ami-05fb0b8c1424f266b" # Specify the AMI ID for your desired Amazon Machine Image
  instance_type          = "t2.large"
  key_name               = "admin-ajay" # Change this to your key pair name
  vpc_security_group_ids = [aws_security_group.terraform-instance-sg.id]


  tags = {
    Name = "Jenkins_Server"
  }
 #for storage
  root_block_device {
    volume_size = 30
  }


}

output "jenkins_public_ip" {
    value = [for instance in aws_instance.my_instance : instance.public_ip]

}



#Create security group 
resource "aws_security_group" "terraform-instance-sg" {
  name        = "terraform-craeted-sg"
  description = "Allow inbound ports 22, 8080"
  vpc_id      = "vpc-0a35a83de5d6649ab"

  #Allow incoming TCP requests on port 22 from any IP
  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  #Allow incoming TCP requests on port 443 from any IP
  ingress {
    description = "Allow HTTPS Traffic"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  ingress {
    description = "Allow Sonar Traffic"
    from_port   = 9000
    to_port     = 9000
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  #Allow incoming TCP requests on port 8080 from any IP
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  #Allow incoming TCP requests on port 8080 from any IP
  ingress {
    from_port   = 8080
    to_port     = 8080
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  

  #Allow all outbound requests
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
```

`Step 2 : Create an IAM role for the newly created EC2 instance.`

Navigate to IAM Roles and click on "Create Role."

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704131323547/d320ad91-efee-4cdc-a0ec-ca774cf10d88.png align="center")

Select "EC2" as the use case and proceed to the next step. Search for "AdministratorAccess" (for learning purposes) and click "Next."

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704131515362/1d072e12-63e1-4cd0-ae28-329460d71786.png align="center")

Provide a name for the role and click "Create Role."

Now, attach the role to the EC2 instance. Choose the instance, then go to Actions &gt; Security &gt; Modify IAM role.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704131896796/4c4453b0-8988-4faf-8e87-b8b622084658.png align="center")

Select the created role from the list and click on "Update IAM role."

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704132110983/fcabcd75-b54e-4284-b56c-320ab6000c34.png align="center")

`Step 3: Install Required packages.`

Install the required packages by SSHing into the EC2 instance.

Create two scripts, namely "`jenkins-docker.sh`" and "`other-packages.sh`"

`jenkins-docker.sh`

```bash
#!/bin/bash
sudo apt update -y
sudo apt install fontconfig openjdk-17-jre -y
java -version
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y
sudo apt-get install jenkins -y
sudo systemctl enable jenkins 
sudo systemctl start jenkins 

#install docker
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg -y
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo usermod -aG docker ubuntu
newgrp docker
```

`other-packages.sh`

```bash
#!/bin/bash
# install trivy
sudo apt-get install wget apt-transport-https gnupg lsb-release -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy -y
#install terraform
sudo apt install wget -y
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
#install Kubectl on Jenkins
sudo apt update
sudo apt install curl -y
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
#install Aws cli
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt-get install unzip -y
unzip awscliv2.zip
sudo ./aws/install
```

Execute both scripts using the following command.

```bash
chmod 777 jenkins-docker.sh
chmod 777 other-packages.sh
./jenkins-docker.sh
./other-packages.sh
```

Verify the installation of all packages.

```bash
docker --version 
trivy --version
aws --version
terraform --version
kubectl version
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704134833033/3bf14981-3423-4653-afad-85095628642b.png align="center")

Grant executable permissions for `docker.sock` and initiate the Docker container for SonarQube.

```bash
sudo chmod 777 /var/run/docker.sock
docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704135090178/848909be-26fe-47a2-b2d1-f8ba33167651.png align="center")

`Step 4: Establish a connection between Jenkins and SonarQube.`

Copy the IP address of the EC2 instance and paste it into the browser.

```bash
<Ec2-ip:8080>
```

It will prompt for a password.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704135495811/5f631531-80c1-42f5-bf77-121b01105244.png align="center")

Retrieve the password and complete the installation.

Jenkins Dashboard.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704135671490/8a339723-af80-4957-a886-f5be165a62b0.png align="center")

Now access SonarQube using:

```bash
<ec2-ip:9000>
```

It will ask for the default username and password. Enter "admin" in both.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704135814421/a532dfc5-92db-419f-85ab-b11e7fcf34f1.png align="center")

The SonarQube dashboard will look like this.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704138602764/789c2c49-969f-42d8-aa5b-c49330fcaa53.png align="center")

`Step 5: Terraform Configuration and EKS Provisioning`

Now, navigate to Jenkins and add the Terraform plugin to facilitate the AWS EKS provisioning through the Pipeline Job.

Follow these steps:

1. Access the Jenkins dashboard –&gt; Manage Jenkins –&gt; Plugins.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704139057575/774a6c19-0b58-41d9-b7f3-89065a9aa5c7.png align="center")

1. In the Available Plugins section, search for "Terraform" and install it.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704139276093/a330cd2b-41e9-4493-9c58-526dab7e5a1c.png align="center")

To determine the path to Terraform, you can use the following command in terminal(Ec2 SSH):

```bash
which terraform
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704139412830/c6af18f6-9d62-4a90-9570-6b8ab7617014.png align="center")

Navigate back to the Jenkins dashboard and follow these steps to add Terraform to the tools:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704139566834/1bd7a574-7a0d-4dfe-8dfc-ef563772973b.png align="center")

Find the section for adding tools, and look for Terraform in the list.

Add Terraform, specifying the name and the path to the Terraform executable on your system (the path you obtained using the `which terraform` command).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704139709658/bca87bc7-ba2a-4976-8919-440d4351c93f.png align="center")

Modify the S3 bucket name in the [`backend.tf`](http://backend.tf) file. If you have forked the Git repository, navigate to the `EKS_terraform` folder and make the necessary changes. Update the S3 bucket name according to your preferences or project requirements. This ensures that Terraform uses the correct backend configuration for storing its state files.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704139870182/b841cf07-f8f7-4ec2-b7e2-97a0c17be283.png align="center")

Create a new Jenkins job for provisioning Amazon EKS. This job will be responsible for managing the deployment and configuration of your EKS cluster.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704140071541/c6de02c1-49f0-4e5b-9f71-5a6ef4725ece.png align="center")

I aim to incorporate build parameters to facilitate the application and destruction processes during the build phase exclusively. Please include the following configuration inside the job, as depicted in the image below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704140255441/f8c63799-7c40-42bb-8fda-897836b98c5b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705337612722/6b342f34-c796-473b-bb09-3589c5a25744.png align="center")

`Pipeline Code:`

```bash

pipeline{
    agent any
    stages {
        stage('Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/patelajay745/uber-clone.git'
            }
        }
        stage('Terraform version'){
             steps{
                 sh 'terraform --version'
             }
        }
        stage('Terraform init'){
             steps{
                 dir('EKS_TERRAFORM') {
                      sh 'terraform init'
                   }
             }
        }
        stage('Terraform validate'){
             steps{
                 dir('EKS_TERRAFORM') {
                      sh 'terraform validate'
                   }
             }
        }
        stage('Terraform plan'){
             steps{
                 dir('EKS_TERRAFORM') {
                      sh 'terraform plan'
                   }
             }
        }
        stage('Terraform apply/destroy'){
             steps{
                 dir('EKS_TERRAFORM') {
                      sh 'terraform ${action} --auto-approve'
                   }
             }
        }
    }
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704140469640/79b6d5a9-7f8d-4ce7-8c65-c9e72687af7e.png align="center")

Click "Save," then proceed to "Build with Parameters." Choose "apply" and click "Build."

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704147702078/9a710368-9088-4a73-9ba5-7b95ac4eb9be.png align="center")

The EKS provisioning process will take some time. If everything is configured correctly, the status will resemble the image below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704150825957/edb29c49-a64c-4766-bb33-5c38d1e45083.png align="center")

Now check created resource in AWS console.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704150915976/aa05c4ea-a916-40c9-b636-83d7edd75eaa.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704150931337/a9f67e94-bfe9-436e-8d9a-9b4256fd5013.png align="center")

`Step 6: Plugin Installation and Setup (Java, Sonar, Node.js, OWASP, Docker)`

Navigate to the Jenkins dashboard.

Go to "Manage Jenkins" → "Plugins" → "Available Plugins."

Search for the following plugins:

1. Eclipse Temurin Installer
    
2. SonarQube Scanner
    
3. NodeJS
    
4. OWASP Dependency-Check
    
5. Docker
    
6. Docker Commons
    
7. Docker Pipeline
    
8. Docker API
    
9. Docker Build Step
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151188623/e315dd8e-1136-46c3-9741-6504a25ab3ff.png align="center")
    

`Step 7: Configuration of Global tools.`

Navigate to "Manage Jenkins" → "Tools" → Install JDK(17) and Node.js(16) → Click on "Apply and Save."

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151486984/2520fbe1-8369-4e93-b585-2d6a992e7b6d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151539373/ac107817-0677-4c6a-b4bb-24e78ff38ff3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151632275/97fdcaaf-2970-4838-a152-556e3e021dc1.png align="center")

For SonarQube:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151717879/e2fa553f-aa68-4b04-8581-d11b70d978d1.png align="center")

For Owasp:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151917878/bfdfc9cf-c1ee-42a4-9957-f5a9aa0610ca.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704151974473/d05c779a-0260-41c1-b9ee-434391449eda.png align="center")

For Docker:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152038458/3d6b8d3e-3d19-479c-9bbf-09d2f0b9ec42.png align="center")

Click on "Apply and Save."  
`Step 8: Configure Sonar Server in Manage Jenkins`

Retrieve the Public IP Address of your EC2 Instance. Since SonarQube operates on Port 9000, access it via &lt;Public IP&gt;:9000.

Visit your SonarQube Server, navigate to Administration → Security → Users, click on Tokens, update the token by assigning it a name, and then generate the token.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152320448/afe512e6-312c-488d-9bbf-08ec095cc604.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152454712/ff454629-eefe-4b42-a9cd-bfd61a3a2767.png align="center")

Enter name of token then click on "Generate"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152538441/55ced296-5945-40e9-bb87-e51b54f95e6d.png align="center")

Copy the token, then go to the Jenkins Dashboard → Manage Jenkins → Credentials → Add Secret Text. The entry should resemble this.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152661858/50031507-639b-45bb-96ed-8c7d9fc75467.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152674752/650d06c9-7812-4b95-ac02-d70a7aa52e89.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152683814/96c3f103-6a2f-4f22-a6d5-cab3ed58e5a4.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704152755939/2b1ca2fe-7b35-4679-aabd-a053a3fdafeb.png align="center")

Now, Navigate to Dashboard → Manage Jenkins → System and Add like the below image.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704153010857/c70c4e69-d25d-47d9-b2cc-fc0386033f2a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704153071079/0fffb586-f7cc-4b2c-8a17-7df9fda5d8c4.png align="center")

Click on "Apply and Save."

In the Sonarqube Dashboard, also include a quality gate by navigating to Administration → Configuration → Webhooks.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704153721646/4c683963-1fed-42bb-b351-26f7b7fe5063.png align="center")

Click on "Create"

```bash
In URL Section:
<http://jenkins-public-ip:8080>/sonarqube-webhook/>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704153856021/00a76733-89b7-4440-9dcf-bf14a46391fd.png align="center")

Now, integrate Docker credentials into Jenkins for logging in and pushing the image:

Navigate to Manage Jenkins → Credentials → Global → Add Credential.

Provide DockerHub Username and Password under Global Credentials.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704154022780/fb151907-4d4b-4bf7-9af3-cfb459e30281.png align="center")

`Step 9: Pipeline up to Docker`

Now, let's create a new job for our pipeline.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704154118054/f74c421b-a571-4667-97fe-da2430010719.png align="center")

Add Following script in pipeline section.

```bash
pipeline{
    agent any
    tools{
        jdk 'jdk17'
        nodejs 'node16'
    }
    environment {
        SCANNER_HOME=tool 'sonar-scanner'
    }
    stages {
        stage('clean workspace'){
            steps{
                cleanWs()
            }
        }
        stage('Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/patelajay745/uber-clone.git'
            }
        }
        stage("Sonarqube Analysis "){
            steps{
                withSonarQubeEnv('sonar-server') {
                    sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Uber \
                    -Dsonar.projectKey=Uber'''
                }
            }
        }
        stage("quality gate"){
           steps {
                script {
                    waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-Token'
                }
            }
        }
        stage('Install Dependencies') {
            steps {
                sh "npm install"
            }
        }
        stage('OWASP FS SCAN') {
            steps {
                dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
         stage('TRIVY FS SCAN') {
            steps {
                sh "trivy fs . > trivyfs.txt"
            }
        }
        stage("Docker Build & Push"){
            steps{
                script{
                   withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
                       sh "docker build -t uber ."
                       sh "docker tag uber patelajay745/uber:latest "
                       sh "docker push patelajay745/uber:latest "
                    }
                }
            }
        }
        stage("TRIVY"){
            steps{
                sh "trivy image patelajay745/uber:latest > trivyimage.txt"
            }
        }
        stage("deploy_docker"){
            steps{
                sh "docker stop uber || true"  // Stop the container if it's running, ignore errors
                sh "docker rm uber || true" 
                sh "docker run -d --name uber -p 3000:3000 patelajay745/uber:latest"
            }
        }
    }
}
```

Click on "Apply and Save."

Click on "Build Now"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155207581/d7c7500b-3782-4243-ae5b-4009b767794e.png align="center")

Now see the reports on SonarQube dashboard.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155260326/a2b84fc3-b6f4-447d-bd00-df338e8959b4.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155346175/f55ba16f-88a6-4abf-9ba8-98afe2433639.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155371393/3ec45ae1-5153-456b-b181-45dd7db3616a.png align="center")

When you log in to Dockerhub, you will see a new image is created

`Step 10: Deployment on EKS`

SSH to Jenkins server and enter following command:

```bash
aws eks update-kubeconfig --name <CLUSTER NAME> --region <CLUSTER REGION>
aws eks update-kubeconfig --name EKS_CLOUD --region us-east-2
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155554508/9c8a73f4-4081-40d1-8689-070a754af1a0.png align="center")

Check status of worker node.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155610964/504cbc0c-8f50-4ef8-ac7f-fde7f2d49edf.png align="center")

Get config file using following code.

```bash
cat ~/.kube/config
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704155748803/bd225b1a-9787-4833-bc95-717438da07c0.png align="center")

Copy it and save it in a document or another folder, naming it secret-file.txt.

Note: Create a file named secret-file.txt in your file explorer, store the configuration within it, and utilize it in the Kubernetes credential section.

Now install required plugin for kubernates in Jenkins.

Go to "Manage Jenkins" → "Plugins" → "Available Plugins."

Search for the following plugins:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704156003591/e9706888-1b41-48ca-9c6b-6fc2f7f73b81.png align="center")

Navigate to Manage Jenkins → Credentials → Global → Add Credential.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704156330993/445d3d4f-787a-4572-9964-39be52be3717.png align="center")

Add Final Stage into pipeline to deploy on the Kubernetes cluster.

```bash
stage('Deploy to Kubernetes') {
            steps {
                script {
                    dir('K8S') {
                        withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8s', namespace: '', restrictKubeConfigAccess: false, serverUrl: '') {
                            // Apply deployment and service YAML files
                            sh 'kubectl apply -f deployment.yml'
                            sh 'kubectl apply -f service.yml'
        
                            // Get the external IP or hostname of the service
                            def externalIP = sh(script: 'kubectl get svc uber-service -o jsonpath="{.status.loadBalancer.ingress[0].hostname}"', returnStdout: true).trim()
        
                            // Print the URL in the Jenkins build log
                            echo "Service URL: http://${externalIP}/"
                        }
                    }
                }
            }
        }
```

Find Weburl from Jenkins Console output.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704157661903/9e6169aa-e707-4cc0-a9e1-21592936bb22.png align="center")

Access on web browser.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704157760487/9e7cd036-6c37-4c56-bfa0-47f29c5429cd.png align="center")

Final pipeline.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704157805088/34a1bffc-092e-41c1-bb20-3b85d2be2a13.png align="center")

`Step 11: Destroy EKS cluster when your done with project.`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704158025085/e42c7f47-a41a-48ad-b93c-0d4e6ace921b.png align="center")

Don't Forget to Destroy Terraform created Ec2 instance for Jenkins server.

### Conclusion

Congratulations on completing the "Jenkins Driven: CI/CD for Uber Clone" project! 🎉 This immersive journey guided you through setting up AWS resources, Terraform provisioning, integrating SonarQube for security scans, and deploying with Docker and Kubernetes. Embrace the power of CI/CD with Jenkins, ensuring a seamless ride from code to production for your Uber-inspired application. 🌐🚀

If you have any questions or feedback, feel free to reach out. Happy coding! 💻🛠️

`For learners: It's okay to make mistakes. Every mistake helps you learn. Check out my pipeline that didn't work. 🚀`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1704162702879/868085e0-a066-4b27-801b-cc6685d6c169.png align="center")
