Netflix Clone CI/CD Pipeline | Jenkins | Docker | Kubernetes | Monitoring | DevSecOps
In these Project, we are cloning the Netflix API using the Bunch of tools. We are using the Grafana and Prometheus for monitoring All the tools. Use the Jenkins for CI/CD and K8s for the Deployment .
Step 1:Launch an Ubuntu(22.04) T2 Large Instance
Step 2 — Install Jenkins, Docker and Trivy
when we will run the pipeline , will get error so , we have to provide permission docker.sock
Installing the SonarQube -
So , Now we are installing Trivy, which is used for Scanning the repository files and scan the Docker images
Install Trivy
Step 3: Create a TMDB API Key
Step 4 — Install Prometheus and Grafana On the new Server
Creating prometheus user
You can use the curl or wget command to download Prometheus.
Then, we need to extract all Prometheus files from the archive.
Create the directory for Prometheus
Now, let's change the directory to Prometheus and move some files.
let's move the Prometheus binary and a promtool to the /usr/local/bin/. promtool is used to check configuration files and Prometheus rules.
The main Prometheus configuration file.
To avoid permission issues, you need to set the correct ownership for the /etc/prometheus/ and data directory.
You can delete the archive and a Prometheus folder when you are done.
Verify that you can execute the Prometheus binary by running the following command:
To get more information and configuration options, run Prometheus Help.
We're going to use Systemd, which is a system and service manager for Linux operating systems. For that, we need to create a Systemd unit configuration file.
Prometheus.service
If , you encounter any issues with Prometheus or are unable to start it. The easiest way to find the problem is to use the journalctl command and search for errors.
Now we can try to access it via the browser. I'm going to be using the IP address of the Ubuntu server. You need to append port 9090 to the IP.
Install Node Exporter on Ubuntu 22.04
First, let's create a system user for Node Exporter by running the following command:
Extract the node exporter from the archive.
Move binary to the /usr/local/bin.
Clean up, and delete node_exporter archive and a folder.
Verify that you can run the binary.
Node Exporter has a lot of plugins that we can enable. If you run Node Exporter help you will get all the options.
Next, create a similar systemd unit file.
node_exporter.service
If you have any issues, check logs with journalctl
To create a static target, you need to add job_name with static_configs.
prometheus.yml
By default, Node Exporter will be exposed on port 9100.
Since we enabled lifecycle management via API calls, we can reload the Prometheus config without restarting the service and causing downtime.
Before, restarting check if the config is valid.
Then, you can use a POST request to reload the config.
Check the targets section
Install Grafana on Ubuntu 22.04
First, let's make sure that all the dependencies are installed.
Next, add the GPG key.
Add this repository for stable releases.
After you add the repository, update and install Garafana.
To automatically start the Grafana after reboot, enable the service.
Go to http://<ip>:3000
and log in to the Grafana using default credentials. The username is admin, and the password is admin as well.
http://<ip>:3000
and log in to the Grafana using default credentials. The username is admin, and the password is admin as well.To visualize metrics, you need to add a data source first.
Click Add data source and select Prometheus.
For the URL, enter localhost:9090 and click Save and test. You can see Data source is working.
Click on Save and Test.
Let's add Dashboard for a better view
Click on Import Dashboard paste this code 1860 and click on load
Select the Datasource and click on Import
You will see this output
Step 5 — Install the Prometheus Plugin and Integrate it with the Prometheus server
Let's Monitor JENKINS SYSTEM
Need Jenkins up and running machine
Goto Manage Jenkins --> Plugins --> Available Plugins
Once that is done you will Prometheus is set to /Prometheus
path in system configurations
Nothing to change click on apply and save
To create a static target, you need to add job_name with static_configs. go to Prometheus server
Paste below code
Before, restarting check if the config is valid.
Then, you can use a POST request to reload the config.
Check the targets section
Let's add Dashboard for a better view in Grafana
Click On Dashboard --> + symbol --> Import Dashboard
Use Id 9964
and click on load
Select the data source and click on Import
Now you will see the Detailed overview of Jenkins
Step 6 — Email Integration With Jenkins and Plugin Setup
Install Email Extension Plugin
in Jenkins
Go to your Gmail and click on your profile
Then click on Manage Your Google Account --> click on the security tab on the left side panel you will get this page(provide mail password).
Click on Manage Jenkins--> credentials and add your mail username and generated password
This is to just verify the mail configuration
Now under the Extended E-mail Notification section configure the details as shown in the below images
Click on Apply and save.
Step 7 — Install Plugins like JDK, Sonarqube Scanner, NodeJs, OWASP Dependency Check
7A — Install Plugin
Goto Manage Jenkins →Plugins → Available Plugins →
Install below plugins
1 → Eclipse Temurin Installer (Install without restart)
2 → SonarQube Scanner (Install without restart)
3 → NodeJs Plugin (Install Without restart)
Plugins to be Install on the jenkins -
Eclipse Temurin installer PluginVersion1.5 NodeJS PluginVersion1.6.1 SonarQube Scanner for JenkinsVersion2.16.1
7B — Configure Java and Nodejs in Global Tool Configuration
Goto Manage Jenkins → Tools → Install JDK(17) and NodeJs(16)→ Click on Apply and Save
Apply & Save .
Step 8 — Configure Sonar Server in Manage Jenkins
Grab the Public IP Address of your EC2 Instance, Sonarqube works on Port 9000, so :9000. Goto your Sonarqube Server. Click on Administration → Security → Users → Click on Tokens and Update Token → Give it a name → and click on Generate Token
click on update Token
Create a token with a name and generate
copy Token
Goto Jenkins Dashboard → Manage Jenkins → Credentials → Add Secret Text. It should look like this
You will this page once you click on create
Now, go to Dashboard → Manage Jenkins → System and Add like the below image.
Click on Apply and Save
The Configure System option is used in Jenkins to configure different server
Global Tool Configuration is used to configure different tools that we install using Plugins
We will install a sonar scanner in the tools
In the SonarQube Dashboard add a quality gate also
Administration--> Configuration-->Webhooks
Click on Create
Let's go to our Pipeline and add the script in our Pipeline Script.
See , How can we generate the SonarQube-Script (Already added in the Above code)
Click on Set-up -> Locally ->
Click on Build now, you will see the stage view like this
To see the report, you can go to Sonarqube Server and go to Projects.
You can see the report has been generated and the status shows as passed.
Step 9 — Install OWASP Dependency Check Plugins
First, we configured the Plugin and next, we had to configure the Tool
Goto Dashboard → Manage Jenkins → Tools →
Click on Apply and Save here.
Now go configure → Pipeline and add this stage to your pipeline and build.
The stage view would look like this,
You will see that in status, a graph will also be generated and Vulnerabilities.
Step 10 — Docker Image Build and Push
We need to install the Docker tool in our system, Goto Dashboard → Manage Plugins → Available plugins → Search for Docker and install these plugins
Docker
Docker Commons
Docker Pipeline
Docker API
docker-build-step
and click on install without restart
Now, goto Dashboard → Manage Jenkins → Tools →
Add DockerHub Username and Password under Global Credentials
Add this stage to Pipeline Script
You will see the output below, with a dependency trend.
When you log in to Dockerhub, you will see a new image is created
Now Run the container to see if the game coming up or not by adding the below stage
stage view
<Jenkins-public-ip:8081>
You will get this output
Step 11 — Kuberenetes Setup
Connect your machines to Putty or Mobaxtreme
Take-Two Ubuntu 20.04 instances one for k8s master and the other one for worker.
Install Kubectl on Jenkins machine also.
Part 1 ----------Master Node------------
----------Worker Node------------
Part 2 ------------Both Master & Node ------------
Part 3 --------------- Master ---------------
----------Worker Node------------
Copy the config file to Jenkins master or the local file manager and save it
copy it and save it in documents or another folder save it as secret-file.txt
Note: create a secret-file.txt in your file explorer save the config in it and use this at the kubernetes credential section.
Install Kubernetes Plugin, Once it's installed successfully
goto manage Jenkins --> manage credentials --> Click on Jenkins global --> add credentials
Install Node_exporter on both master and worker
Let's add Node_exporter on Master and Worker to monitor the metrics
First, let's create a system user for Node Exporter by running the following command:
You can download Node Exporter from the same page.
Use the wget command to download the binary.
Extract the node exporter from the archive.
Move binary to the /usr/local/bin.
Clean up, and delete node_exporter archive and a folder.
Verify that you can run the binary.
Node Exporter has a lot of plugins that we can enable. If you run Node Exporter help you will get all the options.
--collector.logind We're going to enable the login controller, just for the demo.
Next, create a similar systemd unit file.
Replace Prometheus user and group to node_exporter, and update the ExecStart command.
To automatically start the Node Exporter after reboot, enable the service.
If you have any issues, check logs with journalctl
At this point, we have only a single target in our Prometheus. There are many different service discovery mechanisms built into Prometheus. For example, Prometheus can dynamically discover targets in AWS, GCP, and other clouds based on the labels. In the following tutorials, I'll give you a few examples of deploying Prometheus in a cloud-specific environment. For this tutorial, let's keep it simple and keep adding static targets. Also, I have a lesson on how to deploy and manage Prometheus in the Kubernetes cluster.
To create a static target, you need to add job_name with static_configs. Go to Prometheus server
prometheus.yml
Since we enabled lifecycle management via API calls, we can reload the Prometheus config without restarting the service and causing downtime.
Before, restarting check if the config is valid.
Then, you can use a POST request to reload the config.
Check the targets section
final step to deploy on the Kubernetes cluster
How to set a path of Kubernetes
goto pipeline syntax -> sample step -> withkube config -> credentials is the secrete k8s.txt
-> generate the path
Stage View
In the Kubernetes cluster(master) give this command
STEP 12:Access from a Web browser with
Output -
Monitoring -
Complete Pipeline
Step 13: Terminate instances.
Last updated