End-To-End Devops Ci/Cd Pipeline Project: Phase-1: Kubernetes Cluster Set-Up
End-To-End Devops Ci/Cd Pipeline Project: Phase-1: Kubernetes Cluster Set-Up
unzip awscliv2.zip
sudo ./aws/install
export PATH=$PATH:/usr/local/bin/
• GO TO IAM A SERVICE.
• CLICK ON ROLES.
• CLICK ON NEXT
• IN MY CASE I SELECT ADMINISTRATION ACCESS
( bucket name)
• GO TO PROPERTIES
• CLICK ON EDIT
export KOPS_STATE_STORE=s3://praveenfirstbucket.kopsbucket.k8s.local
TO CHECK NODES:
kubectl get no
echo \
The below command grants all users read and write access to the Docker socket, allowing
them to run Docker commands without sudo.
sudo chmod 666 /var/run/docker.sock
• Access the Sonarqube & Nexus using Instance public_ip with host-port.
Your provided commands are correct for accessing the Nexus password stored in the
container. Here's a breakdown of the steps:
1. Get Container ID: You need to find out the ID of the Nexus container. You can do
this by running:
docker ps
This command lists all running containers along with their IDs, among other information.
2. Access Container's Bash Shell: Once you have the container ID, you can execute
the docker exec command to access the container's bash shell:
3. Navigate to Nexus Directory: Inside the container's bash shell, navigate to the
directory where Nexus stores its configuration:
cd sonatype-work/nexus3
4. View Admin Password: Finally, you can view the admin password by displaying the
contents of the admin.password file:
cat admin.password
5. Exit the Container Shell: Once you have retrieved the password, you can exit the
container's bash shell:
exit
This process allows you to access the Nexus admin password stored within the container.
Make sure to keep this password secure, as it grants administrative access to your Nexus
instance.
SET-UP JENKINS.
http://<public-ip>:8080
To retrieve the Jenkins administrator password, access the following file inside the instance:
/var/lib/jenkins/secrets/initialAdminPassword
"Install suggested plugins" – Click this option to install commonly used plugins
automatically.
o Go to GitHub/GitLab/Bitbucket.
o Create a new repository and set it as private.
7. Enter Credentials
https://trivy.dev/v0.18.3/installation/
4. Add authentication token (generate from SonarQube under My Account > Security).
5. Click Save.
Configure Quality Gate in SonarQube:
kind: ServiceAccount
metadata:
name: jenkins-sa
namespace: webapps
2. Create a Role with Required Permissions
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: jenkins-role
namespace: webapps
rules:
- apiGroups: [""]
3. Create a RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: jenkins-rolebinding
namespace: webapps
subjects:
- kind: ServiceAccount
name: jenkins-sa
namespace: webapps
roleRef:
kind: Role
name: jenkins-role
apiGroup: rbac.authorization.k8s.io
apiVersion: v1
kind: Secret
metadata:
name: jenkins-sa-token
namespace: webapps
annotations:
kubernetes.io/service-account.name: "jenkins-sa"
type: kubernetes.io/service-account-token
5. Retrieve the Token and Add it to Jenkins Credentials
7. Save.
Now, Jenkins can authenticate with the Kubernetes cluster using this secret.
1. Go to Jenkins Dashboard.
2. Click on "Manage Jenkins" > "Configure System".
o Click "Test".
Pipeline:
pipeline {
agent any
tools {
jdk 'jdk17'
maven 'maven3'
environment {
stages {
stage('Clean Workspace') {
steps {
cleanWs()
stage('Git Checkout') {
steps {
stage('Compile') {
steps {
sh "mvn clean compile"
stage('Test') {
steps {
sh "mvn test"
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('mysonar') {
sh """
$SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectName=BoardGame \
-Dsonar.projectKey=BoardGame \
-Dsonar.java.binaries=.
"""
}
stage('Quality Gate') {
steps {
script {
waitForQualityGate abortPipeline: false
}
stage('Build') {
steps {
sh "mvn package"
}
steps {
script {
}
}
}
steps {
script {
stage('Deploy To Kubernetes') {
steps {
withKubeConfig(
credentialsId: 'k8-token',
clusterName: 'praveen.k8s.local',
namespace: 'webapps',
serverUrl: 'https://api-praveen-k8s-local-g5jpi5-c725fdd012a56dac.elb.ap-south-
1.amazonaws.com'
){
sh "kubectl apply -f deployment-service.yaml -n webapps"
sleep 60
steps {
withKubeConfig(
credentialsId: 'k8-token',
clusterName: 'praveen.k8s.local',
namespace: 'webapps',
serverUrl: 'https://api-praveen-k8s-local-g5jpi5-c725fdd012a56dac.elb.ap-south-
1.amazonaws.com') {
post {
always {
script {
</div>
<p>Check the <a href="${BUILD_URL}">console output</a>.</p>
</div>
</body>
</html>
"""
emailext (
subject: "${jobName} - Build ${buildNumber} -
${pipelineStatus.toUpperCase()}",
body: body,
to: 'tiwork2233@gmail.com',
from: 'jenkins@example.com',
replyTo: 'jenkins@example.com',
mimeType: 'text/html',
attachmentsPattern: 'trivy-image-report.html'
}
}
Build is completed
Sonarqube-quality analysis:
https://prometheus.io/download/
Access the Prometheus :
Install Grafana:
https://grafana.com/grafana/download
• Targets in promethus.
• In Grafana add Prometheus as data source.