0% found this document useful (0 votes)
30 views35 pages

Jenkins End-to-End Implementation

Uploaded by

akshitamhatre43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views35 pages

Jenkins End-to-End Implementation

Uploaded by

akshitamhatre43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

JENKINS END TO END CICD

IMPLEMENTAION
Goal:

Build a spring boot based Java application using Maven and deploy this
application on kubernetes using CICD

We accomplish this by adhering to the procedure outlined below, which integrates CI/CD
implementation at each stage
Activities in this project:
✓Build a Java application using Maven including configuration & installation
✓Setup a sonar server locally and send the report of code execution(static code analysis) to sonarqube
✓Build a docker image for the artifact and push it to dockerhub
✓Automatically update the manifest repository or source code repository using a shell script
✓Deploy the manifest automatically to a Kubernetes cluster using Argo CD

Step1:
Set up an EC2 instance in your AWS account, utilizing Ubuntu with an instance type of t2.large to
effectively utilize resources such as 2 CPUs and 8GB of memory, which are sufficient for this project

Checkout below video by Abhishek Veermalla , if you have any doubts on how to create EC2 instance.

https://youtu.be/MkIRh1mi8Ms?si=ZXblEOUZ3xw_jQZp
Checkout below github repo url where you can find code for this project
Note: Its created by Abhishek veermalla – creator of this project)

https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero

Step2:

1)Lets move to Jenkins part

Login to EC2 instance using ssh


command: ssh –i /Downloads/sakeena-aws-pem-file.pem ubuntu@ 100.24.255.244 (public ip)
2)Install java as a prerequisite for Jenkins
sudo apt update
sudo apt install openjdk-11-jre
❖ By default Jenkins server will be started by port 8080, when you try to access localhost 8080 it will not
be started
so we have to configure the inbound traffic rules on EC2 instance( security rules which prevents the
incoming traffic unless we enable the port for the EC2 instance)

we have selected All traffic here ,but in real time environment restrict it as per your requirement.

To check if Jenkins is running use below


ps –ef | grep Jenkins
Login to Jenkins using your ec2 instance ip appdress
eg: http://<instance ip address>:8080/
Cat the password as below or you can set username and password by your own

❖ Login to Jenkins using the password you got in above command


now you are ready to use the Jenkins

❖ Now click on new item and select pipeline and click on ok

❖Jenkins allows you to write your code in two ways , you can write under script section in Jenkins or
you can put your Jenkins file in git repo where your source code is available

❖ Usually in real time, organizations will manage the Jenkins file in same folder where your
application code is available i.e,. in Git repo
we have to give the Jenkins file path in your Jenkins configuration as below
The purpose of Jenkins file is to execute all the other tasks of the continuous integration.

➢We now need to install the Docker Pipeline plugin, which already includes Maven, located at the
following path

Dashboard -> manage Jenkins ->Plugins -> Available plugins -> Docker pipeline -> install without restart

➢To install sonar server, install sonar service under below path

Dashboard -> manage Jenkins -> Plugins -> Available Plugins ->SonarQubeScanner -> install without restart

➢To install sonar sever on ec2 instance

use apt install unzip to install unzip package before downloading sonarqube

sudo su – sonarqube -> to get in to sonarqube folder


unzip * -> To extract sonarqube folder

Checkout below Readme file where you have steps to install sonarqube

https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero/blob/main/java-maven-sonar-argocd-helm-
k8s/spring-boot-app/README.md

By default sonar will be started on port 9000


➢To Authenticate Jenkins with sonar follow below:

Go to sonarqube -> my account-> security ->give token name as Jenkins and generate token

Copy the token, go to Jenkins -> click on Manage Jenkins ->credentials ->system ->global
credentials -> add credentials -> add sonarqube authentication here
❑Install Docker on your ec2-instance

command: sudo apt install docker.io

Grant permissions to all users like Jenkins, ubuntu etc to avoid any permission issues

command: usermod –aG docker jenkins


usermod –aG docker ubuntu
systemctl restart docker -> to restart docker
▪ Go back and restart your jenkins(its a good practice to restart jenkins when any plugin is installed or
any activity done from our end)

eg: http://100.24.255.244:8080/restart

▪ Now We have to configure docker credentials and github credentials inside jenkins

▪ To configure dockerhub cred:

Dashboard=>Manage jenkins -> Credentials -> system-> global credentials->adduser


Username will be your dockerhub username
ID is based on the name we have provided in the jenkins file as per the jenkins credential store

▪ To configure github cred:

To get access key -> go to your github account -> settings -> developer settings ->personal access tokens-
>Tokens(classic) ->generate new token ->generate new token(classic)-> copy token to your jenkins
dashboard in same path(Dashboard=>Manage jenkins -> Credentials -> system-> global credentials)
Now restart jenkins as we did above configuration to get the changes reflected

Run build and check the console output :

Things we automated v ia Jenkins like below:

➢ Create Container
➢ Checkout SCM
➢ Should push dockerhub image
➢ Should create sonarqube report
➢ Should update the image on dockerhub with build number automatically (shell script to update the
manifest folder)

Stage1: Creating container, Jenkins has to start creating a container and executing the container
Stage 2:

Maven will create the jar file


here maven target(mvn clean package) is downloading a lot of packages and its dependencies and it will
create a jar file, This step is important as all other steps based on creation of this jarfile
Stage 3: mvn sonar:sonar will be executed and pushes the report to sonarqube
Stage 4:

Docker image has to be created which will be configured in your jenkins file
with the same name, image should get created on docker hub
Stage 5:

Final step using shell script to update the manifest folder


Lets move on to CD part now,

To install kubectl follow below documentation as per your OS


https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/

To install minikube use below doc

https://minikube.sigs.k8s.io/docs/start/

Note: follow steps and documentation based in your OS


To install argo CD using operators( which will manage lifecycle of kubernetes controllers)
https://operatorhub.io/operator/argocd-operator

Run all commands sequentially as mentioned in doc to installed argocd


To check whether your Argocd operator is installed use below command
kubectl get pods –n operators
minikube status

Use below documentation to get started with argocd implementation

https://argocd-operator.readthedocs.io/en/latest/usage/basics/
❖ To create argocd controller , create vi file with below example(mentioned in above doc )

eg: apiVersion: argoproj.io/v1alpha1


kind: ArgoCD
metadata:
name: example-argocd
labels:
example: basic
spec: {}

❖ Run below commands to get the argocd workloads being created


Commands:
kubectl apply –f argocd-basic.yml
kubectl get pods (to check status)
❖ Execute below command which is responsible to run the argocd ui on your browser
Kubectl get svc
kubectl edit svc example-argocd-server (to change the type from ClusterIP to NodePort)

❖ Below command can also be passed directly:

kubectl patch svc example-argocd-server -n argocd -p '{"spec": {"type": “NodePort"}}'


To execute it on browser , use minikube feature by executing below command

minikube service list -> lists all the services exposed by minikube
minikube service example-argocd-server -> to expose specific service
In case if tunneling is not happening use below command

kubectl port-forward svc/example-argocd-server -n default --address 0.0.0.0 8080:443

Tunneling in Minikube enables access to Kubernetes cluster services from the host machine
by forwarding traffic through a secure channel. It facilitates seamless interaction with
applications and services running within the cluster for development and testing purposes
Now you should be able to login argocd ui on your browser

Username is admin by default


And for password , use below below command
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
; echo

Click on create application tab and start creating your first application☺
Click on create, you will see that application will be automatically created using kubernetes cluster as
argocd will fetch your application info from github repo
You can use below command to check whether the application is deployed

kubectl get deploy

You might also like