DecSecOps Project
DecSecOps Project
🔍 Project Overview:
This project demonstrates a comprehensive DevSecOps pipeline for deploying a
Netflix clone application on AWS, leveraging Jenkins, Docker, SonarQube, Trivy,
Prometheus, Grafana, and Kubernetes.
Step-2) Clone Code Repository - Clone the Netflix clone code from GitHub.
https://github.com/mayur4279/DevSecOps-Project-Netflixapp.git
Step-3) Install Docker - Set up Docker and build the application container.
newgrp docker
Step-5) API Key Integration - Retrieve and integrate TMDB API key into the
application.
Open a web browser and navigate to TMDB (The Movie Database) website.
Click on "Login" and create an account.
Once logged in, go to your profile and select "Settings."
Click on "API" from the left-side panel.
Create a new API key by clicking "Create" and accepting the terms and
conditions.
Provide the required basic details and click "Submit."
You will receive your TMDB API key.
Step-6) Now recreate the Docker image with your api key:
Successfully able to run our Netflix clone application using Docker container.
Phase 2: CI/CD Setup using Jenkins along with security tools like (trivy &
SonarQube)
SonarQube:
Trivy:
java -version
#jenkins
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
Step-4) Access Jenkins in a web browser using the public IP of your EC2 instance.
<PublicIp>:8080
- Create Token:
Select the Administration option in SonarQube
pipeline{
agent any
tools{
jdk 'jdk17'
nodejs 'node16'
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
stages {
stage('clean workspace'){
steps{
cleanWs()
steps{
steps{
withSonarQubeEnv('sonar-server') {
-Dsonar.projectKey=Netflix '''
}
stage("quality gate"){
steps {
script {
echo "done"
stage('Install Dependencies') {
steps {
sh "npm install"
stage('OWASP FS SCAN') {
steps {
echo "done"
stage('TRIVY FS SCAN') {
steps {
}
stage("Docker Build & Push"){
steps{
script{
stage("TRIVY"){
steps{
stage('Deploy to container'){
steps{
}
Successfully run our pipeline.
Download Prometheus:
wget
https://github.com/prometheus/prometheus/releases/download/v2.47.1/
prometheus-2.47.1.linux-amd64.tar.gz
cd prometheus-2.47.1.linux-amd64/
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/data \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
Here's a brief explanation of the key parts in this prometheus.service file:
User and Group specify the Linux user and group under which Prometheus
will run.
ExecStart is where you specify the Prometheus binary path, the location of
the configuration file (prometheus.yml), the storage directory, and other
settings.
web.listen-address configures Prometheus to listen on all network
interfaces on port 9090.
web.enable-lifecycle allows for management of Prometheus through API
calls.
You can access Prometheus in a web browser using your server's IP and port 9090:
http://<your-server-ip>:9090
Create a system user for Node Exporter and download Node Exporter:
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
User=node_exporter
Group=node_exporter
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/node_exporter --collector.logind
[Install]
WantedBy=multi-user.target
Prometheus Configuration:
To configure Prometheus to scrape metrics from Node Exporter and Jenkins, you
need to modify the prometheus.yml file. Here is an
http://<your-prometheus-ip>:9090/targets
This error is showing because we are not added Prometheus metrics plugin in
Jenkins so let’s add it...
After adding plugin our Premetheus server started capturing the matrises from jenkins..
Installing Grafana (In grafana instance):
Open a web browser and navigate to Grafana using your server's IP address. The
default port for Grafana is 3000.
For example:
http://<your-server-ip>:3000
You'll be prompted to log in to Grafana. The default username is "admin," and the
default password is also "admin."
To visualize metrics, you need to add a data source. Follow these steps:
Click on the gear icon (⚙) in the left sidebar to open the "Configuration"
menu.
Select "Data Sources."
Click on the "Add data source" button.
Choose "Prometheus" as the data source type.
In the "HTTP" section:
o Set the "URL" to http://localhost:9090 (assuming Prometheus is
running on the same server).
o Click the "Save & Test" button to ensure the data source is working.
Click on the "+" (plus) icon in the left sidebar to open the "Create" menu.
Select "Dashboard."
Click on the "Import" dashboard option.
Enter the dashboard code you want to import (e.g., code 1860).
Click the "Load" button.
Select the data source you added (Prometheus) from the dropdown.
Click on the "Import" button.
You should now have a Grafana dashboard set up to visualize metrics from
Prometheus.
That's it! successfully installed and set up Grafana to work with Prometheus for
monitoring and visualization….
Phase 5: Kubernetes:
Node Exporter component allows you to collect system-level metrics from your
cluster nodes.
Steps:-
./get_helm.sh
Step-2) Add the Prometheus Community Helm repository:
Replace 'your-job-name' with a descriptive name for your job. The static_configs
section specifies the targets to scrape metrics from, and in this case, it's set to
nodeip:9001.
echo $ARGOCD_SERVER
echo $ARGO_PWD
To Access the app make sure port 30007 is open in your security group and then
open a new tab paste your NodeIP:30007, your app should be running.
Boom!! Now You can access you Netflix clone app using NodeIp