CICD
CICD
CICD
Phase-1
Create 3 EC2 Instances with 30GB RAM and choose t2.medium
EKS-Setup:
below policies
AmazonEC2FullAccess
AmazonEKS_CNI_Policy
AmazonEKSClusterPolicy
AmazonEKSWorkerNodePolicy
AWSCloudFormationFullAccess
IAMFullAccess
KUBECTL
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-
01-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version --short --client
EKSCTL
curl --silent --location
"https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(una
me -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version
SonarQube Setup:
username: admin
password:admin
Nexus Setup:
then run
cat /nexus-data/admin.password
Username: admin
Password: 66db8137-b229-4682-a789-10655502bd3b ###Replace your password
Phase-2
Close the repository and create your own repository and push those into your github
repository
1.clone the repo:
git clone https://github.com/Madeep9347/cicd-project7.git
2. change the remote repo
git remote set-url origin https://github.com/Madeep9347/cicd-project7.git
→ replace with your github repo
git remote add new-origin https://github.com/Madeep9347/cicd-project7.git\
→replace with your github repo
3. Initialize Git Repository
git init
4. Add Files to Git:
Stage all files for the first commit:
git add .
5. Commit Files:
Commit the staged files with a commit message:
git commit -m "Initial commit"
6. Push to GitHub:
Push the local repository to GitHub:
git push -u origin main
Sonarqube scanner→ This is the tool that actually scans your code and sends the results to
the SonarQube server.
Sonarqube server→ Displays analysis results.
Nexus Configuration:
Update your pom.xml file with your nexus repositories
Copy the maven-releases URL , maven-snapshots URL and update in the pom.xml file
“”
<url>http://54.242.176.54:8081/repository/maven-releases/</url>
<url>http://54.242.176.54:8081/repository/maven-snapshots/</url>
“”
Nexus authentication with Jenkins:
Go to→ manage Jenkins→manage files→add new config→ select global mavensettings.xml,
id=maven-setting → click on next
Go to content
Add the servers with name, username and password
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
namespace: webapps
Create Role
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: app-role
namespace: webapps
rules:
- apiGroups:
- ""
- apps
- autoscaling
- batch
- extensions
- policy
- rbac.authorization.k8s.io
resources:
- pods
- secrets
- componentstatuses
- configmaps
- daemonsets
- deployments
- events
- endpoints
- horizontalpodautoscalers
- ingress
- jobs
- limitranges
- namespaces
- nodes
- pods
- persistentvolumes
- persistentvolumeclaims
- resourcequotas
- replicasets
- replicationcontrollers
- serviceaccounts
- services
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
name: mysecretname
annotations:
kubernetes.io/service-account.name: myserviceaccount
tools {
jdk 'jdk17'
maven 'maven3'
environment {
SCANNER_HOME = tool 'sonar-scanner'
}
stages {
stage('Git Checkout') {
steps {
git branch: 'main', url: 'https://github.com/Madeep9347/cicd-project7.git'
}
}
stage('Compile') {
steps {
sh "mvn compile"
}
}
stage('Test') {
steps {
sh "mvn package -DskipTests=true"
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar') {
sh '''$SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectKey=Mission \
-Dsonar.projectName=Mission \
-Dsonar.java.binaries=.'''
}
}
}
stage('Build') {
steps {
sh "mvn package -DskipTests=true"
}
}
stage('Deploy Artifacts To Nexus') {
steps {
withMaven(globalMavenSettingsConfig: 'maven-setting', jdk: 'jdk17', maven:
'maven3', mavenSettingsConfig: '', traceability: true) {
sh "mvn deploy -DskipTests=true"
}
}
}
emailext (
subject: "${jobName} - Build ${buildNumber} - ${pipelineStatus.toUpperCase()}",
body: body,
to: '[email protected]',
from: '[email protected]',
replyTo: '[email protected]',
mimeType: 'text/html',
attachmentsPattern: 'trivy-image-report.html'
)
}
}
}
}
Access the Application using the External-ip
http://ac7b1a92512c243848be2a7df6fcee96-328134965.ap-south-
1.elb.amazonaws.com:8080/addMission?
Setup Prometheus,Grafana,node-exporter,blackbox-
exporter
Install Node Exporter in Jenkins server
- job_name: 'node_exporter'
static_configs:
- targets: ['18.207.3.152:9100'] # replace with your public-ip
- job_name: 'blackbox_exporter'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- http://localhost:9115
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 18.207.3.152:9115 # replace with your public-ip
4. Run Prometheus:
./prometheus &
5. Verify Prometheus is Running:
Open a web browser and navigate to http://18.207.3.152:9090.
Configure Grafana
1. Add a Data Source:
Navigate to Configuration > Data Sources.
Click Add data source.
Choose your desired data source type (e.g., Prometheus).
Configure the data source with the appropriate URL
(e.g., http://localhost:9090 for Prometheus).
Click Save & Test.
Save and Test.
Next goto→ dashboards→Create Dashboard→ Import dashboard
For node-exporter dashboard-id is 1860 import that and select datasource
You will get visualization dashboard for Jenkins server