Production Level CICD Pipeline Project Notes
Production Level CICD Pipeline Project Notes
Divya Satpute
@TeaCode1122
@TeaCode1122
Divya satpute
1. Setup Repo
3. Configure Tools
Prerequisites
Step 1
Setting up EKS Cluster Using Terraform
AWS Console launch server for terraform
t2 medium
40 storage
update repo
unzip awscliv2.zip
sudo ./aws/install
@TeaCode1122
Divya satpute
AWS Configure Provide Access key and Secret key on Aws Console
aws configure
Install Kubectl
$chmod +x ./kubectl
Installation of Terafform
terraform --version
change directory
$cd FullStack-Blogging-App/
change directory
$cd EKS_Terraform/
AND in main.tf file you just need to change region and availability zone as per your requirement
@TeaCode1122
Divya satpute
$terraform init
$terraform plan
In Order to communicate with aws eks cluster we need to update our kubeconfig file
Step 2
40 GB Storage
t2.large
40 GB storage
@TeaCode1122
Divya satpute
Installation Jenkins
step 1
Install java (latest stable version)
Install Jenkins
$vi 1.sh
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
$./1.sh
@TeaCode1122
Divya satpute
change permission
chmod +x ./kubectl
@TeaCode1122
Divya satpute
Install docker
Create container
our Nexus up and running but password is stored inside the container so for that we need to go
inside the container
$cd sonatype-work/nexus3/
$cat admin.password
Now You Can See Our Nexus also working fine and able to sign in
@TeaCode1122
Divya satpute
Nexus Configuration
Go to nexus dashboard --> click on settings ---> click on repositories
copy the Maven-releases URL and Maven snapshot URL and paste it on POX.XML file
@TeaCode1122
Divya satpute
for credentials go to Jenkins Dashboard --->click on manage Jenkins---> Managed files---> click on
Add new Config--->Global Maven settings.xml--->provide id "anything"---> click on next
Install docker
Create container
@TeaCode1122
Divya satpute
Configuration on Jenkins
Installation Plugins
SonarQube Scanner
Maven Integration
Kubernetes
Kubernetes Credentials
Kubernetes CLI
Docker Pipeline
Docker Commons
Docker
@TeaCode1122
Divya satpute
Configuration System
Sonar Scanner
Configuration tools
Go to Manage jenkins ----> tools
add Maven
Add Docker
@TeaCode1122
Divya satpute
@TeaCode1122
Divya satpute
@TeaCode1122
Divya satpute
Deployment
Create Service Account, Role & Assign that role, And create a secret for Service Account and
generate a Token
Create namespace
$vi svc.yml
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
namespace: webapps
Create Role
$vi role.yml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
@TeaCode1122
Divya satpute
metadata:
name: app-role
namespace: webapps
rules:
- apiGroups:
- ""
- apps
- autoscaling
- batch
- extensions
- policy
- rbac.authorization.k8s.io
resources:
- pods
- componentstatuses
- configmaps
- daemonsets
- deployments
- events
- endpoints
- horizontalpodautoscalers
- ingress
- jobs
- limitranges
- namespaces
- nodes
- secrets
- pods
- persistentvolumes
- persistentvolumeclaims
- resourcequotas
@TeaCode1122
Divya satpute
- replicasets
- replicationcontrollers
- serviceaccounts
- services
$vi bind.yml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: app-rolebinding
namespace: webapps
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: app-role
subjects:
- namespace: webapps
kind: ServiceAccount
name: jenkins
for token
vi jen.secret.yml
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
name: mysecretname
annotations:
kubernetes.io/service-account.name: jenkins
@TeaCode1122
Divya satpute
--docker-server=https://index.docker.io/v1/ \
--docker-username=divyasatpute \
--docker-password=123654 \
--namespace=webapps
Pipeline
pipeline {
agent any
tools {
jdk 'jdk17'
maven 'maven3'
environment{
@TeaCode1122
Divya satpute
stages {
stage('Git Checkout') {
steps {
stage('Compile') {
steps {
sh 'mvn compile'
stage('Test') {
steps {
sh 'mvn test'
stage('Trivy fs scan') {
steps {
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh '''$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Blogging-app -
Dsonar.projectKey=Blogging-app \
-Dsonar.java.binaries=target'''
@TeaCode1122
Divya satpute
stage('Build') {
steps {
stage('Publish Artifacts') {
steps {
sh 'mvn deploy'
steps {
script{
steps {
stage('Docker Push') {
@TeaCode1122
Divya satpute
steps {
script{
stage('k8-Deploy') {
steps {
sleep 20
steps {
@TeaCode1122
Divya satpute
$wget https://github.com/prometheus/prometheus/releases/download/v3.0.0-
beta.0/prometheus-3.0.0-beta.0.linux-amd64.tar.gz
$wget
https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_export
er-0.25.0.linux-amd64.tar.gz
$cd prometheus-3.0.0-beta.0.linux-amd64
$./prometheus &
$cd prometheus-3.0.0-beta.0.linux-amd64
$vi prometheus.yml
$cd blackbox_exporter-0.25.0.linux-amd64
$./blackbox_exporter &
@TeaCode1122
Divya satpute
For Grafana
$sudo apt-get install -y adduser libfontconfig1 musl
$wget https://dl.grafana.com/enterprise/release/grafana-enterprise_11.2.0_amd64.deb
@TeaCode1122
Divya satpute
Test Results
@TeaCode1122
Divya satpute
@TeaCode1122
Divya satpute
@TeaCode1122