Hello friends, we will be deploying a Netflix clone. We will be using Jenkins as a CICD tool and deploying our application on a Docker container and Kubernetes Cluster and we will monitor the Jenkins and Kubernetes metrics using Grafana, Prometheus and Node exporter. I Hope this detailed blog is useful.
Launch an AWS T2 Large Instance. Use the image as Ubuntu. You can create a new key pair or use an existing one. Enable HTTP and HTTPS settings in the Security Group and open all ports (not best case to open all ports but just for learning purposes it’s okay).
Step 2 — Install Jenkins, Docker and Trivy
2A — To Install Jenkins
Connect to your console, and enter these commands to Install Jenkins
vi jenkins.sh #make sure run in Root (or) add at userdata while ec2 launch
Click on the Login on the top right. You will get this page.
You need to create an account here. click on click here. I have account that’s why i added my details there.
once you create an account you will see this page.
Let’s create an API key, By clicking on your profile and clicking settings.
Now click on API from the left side panel.
Now click on create
Click on Developer
Now you have to accept the terms and conditions.
Provide basic details
Click on submit and you will get your API key.
Step 4 — Install Prometheus and Grafana On the new Server
First of all, let’s create a dedicated Linux user sometimes called a system account for Prometheus. Having individual users for each service serves two main purposes:
It is a security measure to reduce the impact in case of an incident with the service.
It simplifies administration as it becomes easier to track down what resources belong to which service.
To create a system user or system account, run the following command:
–system – Will create a system account. –no-create-home – We don’t need a home directory for Prometheus or any other system accounts in our case. –shell /bin/false – It prevents logging in as a Prometheus user. Prometheus – Will create a Prometheus user and a group with the same name.
Let’s check the latest version of Prometheus from the download page.
You can use the curl or wget command to download Prometheus.
Then, we need to extract all Prometheus files from the archive.
tar -xvf prometheus-2.47.1.linux-amd64.tar.gz
Usually, you would have a disk mounted to the data directory. For this tutorial, I will simply create a /data directory. Also, you need a folder for Prometheus configuration files.
sudo mkdir -p /data /etc/prometheus
Now, let’s change the directory to Prometheus and move some files.
cd prometheus-2.47.1.linux-amd64/
First of all, let’s move the Prometheus binary and a promtool to the /usr/local/bin/. promtool is used to check configuration files and Prometheus rules.
sudo mv prometheus promtool /usr/local/bin/
Optionally, we can move console libraries to the Prometheus configuration directory. Console templates allow for the creation of arbitrary consoles using the Go templating language. You don’t need to worry about it if you’re just getting started.
You can delete the archive and a Prometheus folder when you are done.
cd
rm -rf prometheus-2.47.1.linux-amd64.tar.gz
Verify that you can execute the Prometheus binary by running the following command:
prometheus --version
To get more information and configuration options, run Prometheus Help.
prometheus --help
We’re going to use some of these options in the service definition.
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.
Let’s go over a few of the most important options related to Systemd and Prometheus. Restart – Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached. RestartSec – Configures the time to sleep before restarting a service. User and Group – Are Linux user and a group to start a Prometheus process. –config.file=/etc/prometheus/prometheus.yml – Path to the main Prometheus configuration file. –storage.tsdb.path=/data – Location to store Prometheus data. –web.listen-address=0.0.0.0:9090 – Configure to listen on all network interfaces. In some situations, you may have a proxy such as nginx to redirect requests to Prometheus. In that case, you would configure Prometheus to listen only on localhost. –web.enable-lifecycle — Allows to manage Prometheus, for example, to reload configuration without restarting the service.
To automatically start the Prometheus after reboot, run enable.
sudo systemctl enable prometheus
Then just start the Prometheus.
sudo systemctl start prometheus
To check the status of Prometheus run the following command:
sudo systemctl status prometheus
Suppose 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.
journalctl -u prometheus -f --no-pager
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.
<public-ip:9090>
If you go to targets, you should see only one – Prometheus target. It scrapes itself every 15 seconds by default.
Install Node Exporter on Ubuntu 22.04
Next, we’re going to set up and configure Node Exporter to collect Linux system metrics like CPU load and disk I/O. Node Exporter will expose these as Prometheus-style metrics. Since the installation process is very similar, I’m not going to cover as deep as Prometheus.
First, let’s create a system user for Node Exporter by running the following command:
Replace Prometheus user and group to node_exporter, and update the ExecStart command.
To automatically start the Node Exporter after reboot, enable the service.
sudo systemctl enable node_exporter
Then start the Node Exporter.
sudo systemctl start node_exporter
Check the status of Node Exporter with the following command:
sudo systemctl status node_exporter
If you have any issues, check logs with journalctl
journalctl -u node_exporter -f --no-pager
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.
Then, you can use a POST request to reload the config.
curl -X POST http://localhost:9090/-/reload
Check the targets section
http://<ip>:9090/targets
You will see Jenkins is added to it
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).
2-step verification should be enabled.
Search for the app in the search bar you will get app passwords like the below image
Click on other and provide your name and click on Generate and copy the password
In the new update, you will get a password like this
Once the plugin is installed in Jenkins, click on manage Jenkins –> configure system there under the E-mail Notification section configure the details as shown in the below image
Click on Apply and save.
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.
post {
always {
emailext attachLog: true,
subject: "'${currentBuild.result}'",
body: "Project: ${env.JOB_NAME}<br/>" +
"Build Number: ${env.BUILD_NUMBER}<br/>" +
"URL: ${env.BUILD_URL}<br/>",
to: 'postbox.aj99@gmail.com', #change Your mail
attachmentsPattern: 'trivyfs.txt,trivyimage.txt'
}
}
Next, we will log in to Jenkins and start to configure our Pipeline in Jenkins
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)
7B — Configure Java and Nodejs in Global Tool Configuration
Goto Manage Jenkins → Tools → Install JDK(17) and NodeJs(16)→ Click on Apply and Save
7C — Create a Job
create a job as Netflix Name, select pipeline and click on ok.
Step 8 — Configure Sonar Server in Manage Jenkins
Grab the Public IP Address of your EC2 Instance, Sonarqube works on Port 9000, so <Public IP>: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
Add details
#in url section of quality gate
<http://jenkins-public-ip:8080>/sonarqube-webhook/
Let’s go to our Pipeline and add the script in our Pipeline Script.
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. You can see that there are 3.2k lines it scanned. To see a detailed report, you can go to issues.
Step 9 — Install OWASP Dependency Check Plugins
GotoDashboard → Manage Jenkins → Plugins → OWASP Dependency-Check. Click on it and install it without restart.
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.
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
# in case your in root exit from it and run below commands
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
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:
Replace Prometheus user and group to node_exporter, and update the ExecStart command.
To automatically start the Node Exporter after reboot, enable the service.
sudo systemctl enable node_exporter
Then start the Node Exporter.
sudo systemctl start node_exporter
Check the status of Node Exporter with the following command:
sudo systemctl status node_exporter
If you have any issues, check logs with journalctl
journalctl -u node_exporter -f --no-pager
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
Ajay Kumar Yegireddi is a DevSecOps Engineer and System Administrator, with a passion for sharing real-world DevSecOps projects and tasks. Mr. Cloud Book, provides hands-on tutorials and practical insights to help others master DevSecOps tools and workflows. Content is designed to bridge the gap between development, security, and operations, making complex concepts easy to understand for both beginners and professionals.
Comments
22 responses to “Netflix Clone DevSecOps: CI/CD Pipeline with Jenkins, Docker, Kubernetes & Security”
Sampath
Hi,
This was great. I learned a lot here. Keep up the good work.
I found that you were missing the Trivy installation in above. So I used the code below for the installation.
First of all thanks for sharing such a wonderfull project. My questions is why pipeline always stucks at sonar quality gate. Can we make it faster. it runs fine without quality gate. but when i add that step pipeline stucks for long time.
Thanks
Hey Ajay, thank you for this wonderful project, your documentation was also on point, I am a newbie to Grafana, why while importing the dashboard, why we using number code, what is it?
First of all, thank you for this wonderful project and document. I have a small doubt or request—could you please create a Robot shopping cart project? I’m asking because you explain each point clearly and provide excellent documentation. It would be great to see a project like this from you.
the Tmdb website is not working as of now, tried some alternatives but they didnt worked, can you tell something what to do please, without the api key, movies are not loading in the frontend
Leave a Reply