Skip to content

Latest commit

 

History

History
137 lines (97 loc) · 5 KB

README.md

File metadata and controls

137 lines (97 loc) · 5 KB

About

In this project I've tried setting up a CI/CD pipeline. I've created a basic web app which exposes an api(login), whenever there'a a request, it sends a name and details in json format. Here'a a list of tools which I used:

  • Docker: For contenatization of applications.
  • Minikube: For setting up local K8s cluster.
  • AWS EC2: For setting up a Jenkins server.
  • Jenkins: For setting up CI part.
  • ArgoCD: For the CD part following GitOps principles.

This is how the workflow looks like:

image (5)

Step 1

Containerize the app using Dockerfile given in the project repo.

docker build -t prady0t/pipeline .

Now try to run it.

docker run -it prady0t/pipeline

App should be running at port 3001.

Step 2

Push the image to the Dockerhub registery. (if not authenticated, first do docker login)

docker push prady0t/pipeline

Step 3

Setup a Jenkins server on AWS EC2. Set inbould traffic to Anywhere

image

Login to your AWS account and create a new EC2 instance. Now follow these steps to setup Jenkins on EC2 instance : https://www.jenkins.io/doc/book/installing/linux/#debianubuntu. (You would have to install Java first). Now in the terminal

systemctl status jenkins

Check Jenkins should be in the running state. Copy paste IP of the instance followed by :8080 (default port at which jenkins run) in your browser. You should have a unlock Jenkins page.

image

Now go to your instance's terminal and do :

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Use this as a password to unlock Jenkins. Download suggested pluggins.

Step 4

Setup credentials for Github (using secret text, Github token as secret) and Dockerhub (using username and password).

image

Create a pipeline project in Jenkins.Select these as per given below:

image image image

Save

Step 5

Setting up docker on AWS instance. Why do we need that?(I learned it the hard way) We are running single machine where Jenkins master and slave are same machine. We want nodes to have docker installed so taht we can build images with Jenkins. We would also need a Docker pipeline plugin. Go to aws console and type these commands:

sudo apt-get install docker.io -y
sudo systemctl start docker

Check status:

systemctl status docker

Now we have to give jenkins user and ubuntu user permission to acces docker daemon:

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

Recent debuging, also add :

sudo chmod 777 /var/run/docker.sock

Also restart jenkins.

Now add webhook to github repo. A webhook is basically Jenkins server url followed by //github-webhook/:

image (4)

Now hit build on Jenkins:

image

A build is triggered whenever a commit is pushed to main!

With this we are done with our CI part.

Step 6

Setup ArgoCD cluster on minikube. Just follow all the steps from the docs -> https://argo-cd.readthedocs.io/en/stable/getting_started/ Go to localhost:8080

image

Again for initial login, follow the docs.

Step 7

Create a new app with these settings:

image Screenshot 2023-12-28 at 2 11 02 AM

Click Create

image

Go to the terminal and enter:

kubectl get pods

You will see it automatically created pods which were mentioned in the manifest files!

image

With this we are also done with our CD part.