Ci - CD
Ci - CD
Mitigation:
1. Microservices Architecture – Instead of a monolithic structure,
consider breaking down the application into smaller, independent
services. This allows for better scalability, independent
deployment, and improved maintainability.
2. Automated Testing & CI/CD Pipelines – Implement automated
testing (unit, integration, and end-to-end tests) with CI/CD
pipelines to reduce manual efforts in testing and deployment.
Tool like Jenkins can help.
3. Containerization & Orchestration – Use Docker for
containerization and Kubernetes for orchestration to enable
better modularization, scalability, and ease of deployment.
4. Infrastructure as Code (IaC) – Automate infrastructure
provisioning with tool like Terraform to avoid manual
configuration and speed up deployment.
5. Monitoring & Observability – Utilize monitoring tools like
Prometheus, Grafana, for real-time application monitoring,
logging, and performance tracking.
• Tool: Terraform
• Use Case: Automate cloud infrastructure provisioning AWS using
Infrastructure as Code (IaC).
• Benefits:
o Eliminates manual infrastructure setup.
o Ensures version-controlled, repeatable deployments.
• Tool: Maven
• Use Case: Manage dependencies, automate builds, and package
Java applications.
• Benefits:
o Standardized build process for Java-based applications.
o Simplifies dependency management and project structure.
3. Continuous Integration & Deployment (CI/CD)
• Tool: Jenkins
• Use Case: Automate building, testing, and deploying applications
through pipelines.
• Benefits:
o Ensures frequent integration and fast feedback loops.
o Enables automated deployments with rollback capabilities.
• Tool: Docker
• Use Case: Containerize applications for consistent runtime
environments.
• Benefits:
o Removes environment dependency issues.
o Simplifies deployment across different environments.
• Tool: Kubernetes
• Use Case: Deploy, manage, and scale containerized applications
using Kubernetes pods.
• Benefits:
o Enables microservices architecture for better scalability.
o Provides automated load balancing, self-healing, and
networking.
6. Monitoring & Observability
ExecStart=/root/prometheus-2.48.0-rc.0.linux-amd64/prometheus --
config.file=/root/prometheus-2.48.0-rc.0.linux-
amd64/prometheus.yml
[Install]
WantedBy=multi-user.target
• sudo systemctl daemon-reload
• sudo systemctl status prometheus
• sudo systemctl start prometheus
• systemctl enable Prometheus
# grafana installation :
• wget https://dl.grafana.com/oss/release/grafana-9.1.2-
1.x86_64.rpm
• sudo yum install grafana-9.1.2-1.x86_64.rpm -y
• sudo /bin/systemctl enable grafana-server.service
• sudo /bin/systemctl start grafana-server.service
• sudo /bin/systemctl status grafana-server.service
# <grafana external / public ip>:3000 -- to create exposure on
internet
# node exporter installation
• To be installed on node which we wish to monitor
• wget
https://github.com/prometheus/node_exporter/releases/down
load/v1.4.0-rc.0/node_exporter-1.4.0-rc.0.linux-amd64.tar.gz
• tar -zxvf node_exporter-1.4.0-rc.0.linux-amd64.tar.gz ------to
unzip the package
• create the following file
sudo vi /etc/systemd/system/node_exporter.service
-----------------------------------------------------------------------------------------------
-------------------------------------------------
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=root
Restart=on-failure
ExecStart=/root/node_exporter-1.4.0-rc.0.linux-
amd64/node_exporter
[Install]
WantedBy=multi-user.target
• sudo systemctl daemon-reload
• sudo systemctl status node_exporter
• sudo systemctl start node_exporter -- to enable and start node
exporter
• copy the IP address of the server that want to monitor
• navigate to PROMETHEUS server and go to installation path of
Prometheus
• vi prometheus.yml
• Add the target with valid node_exporter port
• sudo systemctl restart prometheus
• sudo systemctl status Prometheus
• Goto Prometheus server -- <prometheus-external-ip>:9090
• in the query field type up and click on execute to see the list of
servers up for monitoring
# Grafana Portal
• <grafana-external-ip>:3000
• Click on settings button --> Data Source --> Add Data Source -->
Select Prometheus
• paste the prometheus link
• See the Prometheus Data Source Created
Build Deployment Through Jenkins CI /CD Pipeline:
# Navigate to jenkins > new_job and give name for your
project and choose pipeline
Pipeline Script :
pipeline {
agent { label 'Jenkins_worker_2' }
environment {
DOCKERHUB_CREDENTIALS=credentials('capestone_docker')
}
stages {
stage('SCM_Checkout') {
steps {
echo "Perform SCM Checkout"
git 'https://github.com/Deepak1998226/star-agile-insurance-
project.git'
}
}
stage('Application Build') {
steps {
echo "Perform Application Build"
sh 'mvn clean package'
}
}
stage('Login2DockerHub') {
steps {
script {
withCredentials([usernamePassword(credentialsId:
'capestone_docker', usernameVariable:
'DOCKERHUB_CREDENTIALS_USR', passwordVariable:
'DOCKERHUB_CREDENTIALS_PSW')]) {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker
login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
}
}
stage('Publish_to_Docker_Registry') {
steps {
sh "docker push deepak607/insurance-eta-
app:${BUILD_NUMBER}"
sh "docker push deepak607/insurance-eta-app:latest"
}
}
stage('Deploy to Kubernetes Cluster') {
steps {
script {
sshPublisher(publishers: [
sshPublisherDesc(
configName: 'deepak',
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: '''
echo "Testing kubectl connection..."
kubectl version
if [ $? -ne 0 ]; then
echo "kubectl is not working. Exiting."
exit 1
fi
echo "Applying Kubernetes Deployment..."
kubectl apply -f kubedeploy.yaml
''',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '.',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: '*.yaml'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
)
])
}
}
}
}
}
## Navigate back to pipeline project page and click on Build Now
option and verify that build is been scheduled