ArgoCD Kubernetes Deployment - CICD Pipeline

khalid kifayatkhalid kifayat
4 min read

Step 1 : In this step we need to create aws ec2 instance and make sure you select t2.large instance type for this project.

Step 2 : In this step you need to install java(jdk) on your ec2 instance.

sudo apt update
sudo apt install openjdk-11-jre

Verify Java is Installed

java -version

Step 3 : In this step you need to install jenkins on your aws ec2 instance.

Now, you can proceed with installing Jenkins

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

Note: By default, Jenkins will not be accessible to the external world due to the inbound traffic restriction by AWS. Open port 8080 in the inbound traffic rules as show below.

  • EC2 > Instances > Click on

  • In the bottom tabs -> Click on Security

  • Security groups

  • Add inbound traffic rules as shown in the image (you can just allow TCP 8080 as well, in my case, I allowed All traffic).

Step 3 : click on new item

Step 4 : You need to copy the the path whre your jenkins file is located.

Step 5 : Then you need to click on manage jenkins

Step 6 : Then go to the the plugin

and install docker pipeline

Then you need to install sonarqube plugin

Configure a Sonar Server locally

apt install unzip
adduser sonarqube
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.4.0.54424.zip
unzip *
chmod -R 755 /home/sonarqube/sonarqube-9.4.0.54424
chown -R sonarqube:sonarqube /home/sonarqube/sonarqube-9.4.0.54424
cd sonarqube-9.4.0.54424/bin/linux-x86-64/
./sonar.sh start

Hurray !! Now you can access the SonarQube Server on http://<ip-address>:9000

Note : Login and password is : admin

Step 7 : Go to the sonar account click on my account

Then go to the security

Then click on generate tokens

Then go to the credentials

Then click on system

Then go to the global credentials

Then go to the add credentials

Note : then go to the root user and install docker on it

Docker Slave Configuration

Run the below command to Install Docker

sudo apt update
sudo apt install docker.io

Grant Jenkins user and Ubuntu user permission to docker deamon.

usermod -aG docker jenkins
usermod -aG docker ubuntu
systemctl restart docker

Step 8 : Then you need to install minikube on local system or you can install on your ec2 instance. I am installing on my local system because of storage issue.

Step 9 : Then you need to install Argo cd on your local machine using kubernetes operator .you can visit this site to install argo cd (operator.io)

Step 10 : Then you need to go to manage jenkins section and click on credentials

Then click on system

Then click on global credentials

Then click on add credentials

Then you need to add your username and password of your dockerhub account in credentials

Then you need to click on add credentials again and add your github credentials

IMP Note: Then you need to go to your jenkins file in that you will see static code analysis stage and in sonar url you need to add sonarqube server ip address otherwise you will get error.

Finally.......๐Ÿคฉ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

Step 10 : Then there is argo cd which is continuously watching this git repository and whenever there is a change in the git repository take the new pod.yaml or take the new deployment.yam or take the new helm chart and deploy to the kubernetes cluster.

Then you need to give below command in terminal where you install Argo cd.

Firstly you need to create argocd_basic.yaml file you can use below code


apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
metadata:
  name: example-argocd
  labels:
    example: basic
spec: {}
 kubectl apply -f argocd-basic.yaml
 kubectl get pods

 kubectl get svc
 kubectl edit svc example-argocd-server

Them you need to chnage type ClusterrIP to NodePort

kubectl get svc
minikube service list

Note : Then you can copy that url and open in your browser.

kubectl get pods

Then you need to click on advance and then click on accept the risk

kubectl get secret
kubectl edit secret example-argocd-cluster

Note : After running above command you can copy admin.password

echo <paste your password> | base64 -d

Note : after running this command you will get your password then copy your password please ignore last symbol % do not copy it . Then login in your argocd account.

Then paste your url

Note : In namespace you need to write default otherwise you will get error. Then click on create

kubectl get deploy
kubectl get pods
kubectl edit deploy spring-boot-app

Note : Whenever you will edit someting it wil automatically deploy on kubernetes cluster.

0
Subscribe to my newsletter

Read articles from khalid kifayat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

khalid kifayat
khalid kifayat

Skillful Tech Engineer having working experience with creating & managing AI-NLP-Chatbots and Cloud computing Infrastructure deployment, testing, monitoring, scripting, automation, Version control, documentation & system's support.