Skip to content

DotNet Monitoring DevSecOps Pipeline

Level:Intermediate
Time:2-3 hours
Cost:medium
Works locally:Yes
Cloud creds:No
Cleanup:Yes
Reviewed:2026-05-30
Validation:dotnet test DotNet-monitoring

Nested DotNet monitoring app with deployment and test assets.

Outcome Passing pipeline run plus scan/deploy evidence
Tools used .NET, Docker, Kubernetes, Monitoring
Best fit Intermediate - 2-3 hours
Student workstation Repository files Container build Reference architecture Validation proof
  • Install or review: .NET, Docker, Kubernetes, Monitoring.
  • No cloud provider credentials are required by the project metadata.
  • This project can be practiced locally before you publish portfolio evidence.
  • Open the safety guide before running commands that create infrastructure.
Cost and credential stance

Cost risk is medium. Cloud target: no cloud provider. Cloud credentials needed: No. Always use your own account, never commit secrets, and confirm cleanup before creating paid infrastructure.

Use this flow before you run commands:

  1. Read the cost and credential warning above.
  2. Review the validation, troubleshooting, cleanup, and portfolio proof sections below.
  3. Follow the original project guide preserved near the bottom of this page.
  4. Return to the validation and cleanup checks before you capture portfolio evidence.

Run the project validation command before and after meaningful changes:

Terminal window
dotnet test DotNet-monitoring
  • Run dotnet test DotNet-monitoring first so local tooling issues are visible early.
  • If a command fails, check tool versions, working directory, and required environment variables.

Cleanup is available or expected for this lab. Use the cleanup or destroy steps in the guide below, then confirm that local clusters, containers, cloud resources, buckets, state files, and CI secrets are no longer active.

  • Validation command output: dotnet test DotNet-monitoring
  • Screenshot or terminal proof: Passing pipeline run plus scan/deploy evidence
  • Notes explaining what changed, what failed, and how you fixed it
  • Cleanup evidence, especially for cloud or Kubernetes resources

The original README content is preserved here for lab-specific commands and context. Headings are intentionally demoted so the page outline stays focused on the standard lab flow.

Below is the Application Source code for this project
Section titled “Below is the Application Source code for this project”

[

External image reference DevOps-Project-24: DotNet Monitoring
](#source-files-on-github)
External image reference Source image

We will be deploying a .NET-based application. This is an everyday use case scenario used by several organizations. We will be using Jenkins as a CICD tool and deploying our application on a Docker Container and Kubernetes cluster. Hope this detailed blog is useful.

This project shows the detailed metric i.e. CPU Performance of our instance where this project is launched.

🛡️ 2026 DevSecOps Enhancements (What You Will Learn)
Section titled “🛡️ 2026 DevSecOps Enhancements (What You Will Learn)”

This repository’s CI/CD workflows and Docker configurations were significantly hardened to comply with 2026 DevSecOps standards:

  1. GitHub Actions Hardening: The .github/workflows/ci-build.yaml has been upgraded to replace deprecated, End-of-Life Node.js 12 actions (e.g., actions/checkout@v2 -> v4), thwarting known remote code execution vulnerabilities in legacy runners.
  2. Shift-Left Container Security: The build pipeline incorporates a strict Trivy scan. It automatically interrogates the .NET Docker image for CVEs, actively rejecting any build exhibiting CRITICAL or HIGH severity vulnerabilities before it ever reaches the repository or Kubernetes.

Step 1 — Create an Ubuntu T2 Large Instance with 30GB storage

Step 2 — Install Jenkins, Docker and Trivy. Create a Sonarqube Container using Docker.

Step 3 — Install Plugins like JDK, Sonarqube Scanner

Step 4 — Install OWASP Dependency Check Plugins

Step 5 — Configure Sonar Server in Manage Jenkins

Step 6— Create a Pipeline Project in Jenkins using Declarative Pipeline

Step 7 — Install make package

Step 8— Docker Image Build and Push

Step 9 — Deploy the image using Docker

Step 10—Access the Real World Application

Step 11— Kubernetes Set Up

Step 12 — Terminate the AWS EC2 Instance

Now, lets get started and dig deeper into each of these steps :-

Section titled “Now, lets get started and dig deeper into each of these steps :-”

Step 1 — 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.

External image reference Source image

Step 2 — Install Jenkins, Docker and Trivy

2A — To Install Jenkins

Connect to your console, and enter these commands to Install Jenkins

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
sudo apt update
sudo apt install openjdk-17-jdk
sudo apt install openjdk-17-jre
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins

Once Jenkins is installed, you will need to go to your AWS EC2 Security Group and open Inbound Port 8080, since Jenkins works on Port 8080.

External image reference Source image

Now, grab your Public IP Address

<EC2 Public IP Address:8080>
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Unlock Jenkins using an administrative password and install the required plugins.

External image reference Source image

Jenkins will now get installed and install all the libraries.

External image reference Source image

Jenkins Getting Started Screen

External image reference Source image

2B — Install Docker

sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER
sudo chmod 777 /var/run/docker.sock
sudo docker ps

After the docker installation, we create a sonarqube container (Remember added 9000 port in the security group)

External image reference Source image
docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
External image reference Source image
External image reference Source image
External image reference Source image

2C — Install Trivy

sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy -y

Step 3 — Install Plugins like JDK, Sonarqube Scanner, OWASP Dependency Check,

Goto Manage Jenkins →Plugins → Available Plugins →

Install below plugins

1 → Eclipse Temurin Installer (Install without restart)

2 → SonarQube Scanner (Install without restart)

Goto Manage Jenkins →Plugins → Available Plugins →

External image reference Source image

3B — Configure Java in Global Tool Configuration

Goto Manage Jenkins → Tools → Install JDK17→ Click on Apply and Save

External image reference Source image

j

Step 4 — GotoDashboard → Manage Jenkins → Plugins → OWASP Dependency-Check. Click on it and install without restart.

External image reference Source image

First, we configured Plugin and next we have to configure Tool

Goto Dashboard → Manage Jenkins → Tools →

External image reference Source image

Click on apply and Save here.

Grab the Public IP Address of your EC2 Instance, Sonarqube works on Port 9000, sp <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

External image reference Source image

Click on Update Token

External image reference Source image

Create a token with a name and generate

External image reference Source image

Copy this Token

Goto Dashboard → Manage Jenkins → Credentials → Add Secret Text. It should look like this

External image reference Source image

You will this page once you click on create

External image reference Source image

Now, go to Dashboard → Manage Jenkins → Configure System

External image reference Source 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.

External image reference Source image

In the Sonarqube Dashboard add a quality gate also

Administration → Configuration →Webhooks

External image reference Source image

Click on Create

External image reference Source image

Add details

#in url section of quality gate
<http://jenkins-public-ip:8080>/sonarqube-webhook/
External image reference Source image

Click on Apply and Save here.

Step 6 — Create a Pipeline Project in Jenkins using Declarative Pipeline

pipeline {
agent any
tools {
jdk 'jdk17'
}
environment {
SCANNER_HOME = tool 'sonar-scanner'
}
stages {
stage('clean workspace') {
steps {
cleanWs()
}
}
stage('Checkout From Git') {
steps {
git branch: 'master', url: 'https://github.com/devcloudninjas/DevOps-Projects/tree/master/project-24-dotnet-devsecops/DotNet-monitoring'
}
}
stage("Sonarqube Analysis ") {
steps {
withSonarQubeEnv('sonar-server') {
sh """$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Dotnet-Webapp \
-Dsonar.projectKey=Dotnet-Webapp"""
}
}
}
stage("quality gate") {
steps {
script {
waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
}
}
}
stage("TRIVY File scan") {
steps {
sh "trivy fs . > trivy-fs_report.txt"
}
}
stage("OWASP Dependency Check") {
steps {
dependencyCheck additionalArguments: '--scan ./ --format XML ', odcInstallation: 'DP-Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
}
}

Click on Build now, you will see the stage view like this

External image reference Source image

You will see that in status, a graph will also be generated and Vulnerabilities

External image reference Source image

To see the report, you can go to Sonarqube Server and go to Projects.

External image reference Source image

Step 7 — Install make package

sudo apt install make
#### to check version install or not
make -v

Step 8 — 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

External image reference Source image

Now, goto Dashboard → Manage Jenkins → Tools →

External image reference Source image

Add DockerHub Username and Password under Global Credentials

External image reference Source image

In the makefile, we already defined some conditions to build, tag and push images to dockerhub.

External image reference Source image

that’s why we are using make image and make a push in the place of docker build -t and docker push

Add this stage to Pipeline Script

stage("Docker Build & tag"){
steps{
script{
withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
sh "make image"
}
}
}
}
stage("TRIVY"){
steps{
sh "trivy image NotHarshhaa/dotnet-monitoring:latest > trivy.txt"
}
}
stage("Docker Push"){
steps{
script{
withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
sh "make push"
}
}
}
}

When all stages in docker are successfully created then you will see the result You log in to Dockerhub, and you will see a new image is created

External image reference Source image

Stage view

External image reference Source image

Step 9 — Deploy the image using Docker

Add this stage to your pipeline syntax

stage("Deploy to container"){
steps{
sh "docker run -d --name dotnet -p 5000:5000 NotHarshhaa/dotnet-monitoring:latest"
}
}

You will see the Stage View like this,

External image reference Source image

(Add port 5000 to Security Group)

External image reference Source image

And you can access your application on Port 5000. This is a Real World Application that has all Functional Tabs.

Step 10 — Access the Real World Application

External image reference Source image
External image reference Source image

Step 11 — Kubernetes Set Up

Take-Two Ubuntu 20.04 instances one for k8s master and the other one for worker.

Install Kubectl on Jenkins machine as well.

sudo apt update
sudo apt install curl
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
Part 1 — — — — — Master Node — — — — — —
Section titled “Part 1 — — — — — Master Node — — — — — —”
sudo su
hostname master
bash
clear
— — — — — Worker Node — — — — — —
Section titled “— — — — — Worker Node — — — — — —”
sudo su
hostname worker
bash
clear
Part 2 — — — — — — Both Master & Node — — — — —
Section titled “Part 2 — — — — — — Both Master & Node — — — — —”
sudo apt-get update
sudo apt-get install -y docker.io
sudo usermod –aG docker Ubuntu
newgrp docker
sudo chmod 777 /var/run/docker.sock
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo snap install kube-apiserver
Part 3 — — — — — — — — Master — — — — — — — -
Section titled “Part 3 — — — — — — — — Master — — — — — — — -”
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
— — — — — Worker Node — — — — — —
Section titled “— — — — — Worker Node — — — — — —”
sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash>

Now, goto the Master Node

cd .kube/
cat config

Copy the config file to Jenkins master or the local file manager and save it

External image reference Source image

copy it and save it in documents or another folder save it as secret-file.txt

Install Kubernetes Plugin, Once it’s installed successfully

goto manage Jenkins → manage credentials → Click on Jenkins global → add credentials

External image reference Source image

Install Kubernetes Plugin, Once it’s installed successfully

External image reference Source image

Goto manage Jenkins → manage credentials → Click on Jenkins global → add credentials

The final step to deploy on the Kubernetes cluster, add this stage to the pipeline.

stage('Deploy to k8s'){
steps{
dir('K8S') {
withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8s', namespace: '', restrictKubeConfigAccess: false, serverUrl: '') {
sh 'kubectl apply -f deployment.yaml'
}
}
}
}

Before starting a new build remove Old containers.

Output

kubectl get svc
#copy service port
<worker-ip:svc port>
External image reference Source image
External image reference Source image

Step 12 — Terminate the AWS EC2 Instance

Lastly, do not forget to terminate the AWS EC2 Instance.

The complete pipeline script

pipeline{
agent any
tools{
jdk 'jdk17'
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
}
stages {
stage('clean workspace'){
steps{
cleanWs()
}
}
stage('Checkout From Git'){
steps{
git branch: 'master', url: 'https://github.com/devcloudninjas/DevOps-Projects/tree/master/project-24-dotnet-devsecops/DotNet-monitoring'
}
}
stage("Sonarqube Analysis "){
steps{
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Dotnet-Webapp \
-Dsonar.projectKey=Dotnet-Webapp '''
}
}
}
stage("quality gate"){
steps {
script {
waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
}
}
}
stage("TRIVY File scan"){
steps{
sh "trivy fs . > trivy-fs_report.txt"
}
}
stage("OWASP Dependency Check"){
steps{
dependencyCheck additionalArguments: '--scan ./ --format XML ', odcInstallation: 'DP-Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage("Docker Build & tag"){
steps{
script{
withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
sh "make image"
}
}
}
}
stage("TRIVY"){
steps{
sh "trivy image NotHarshhaa/dotnet-monitoring:latest > trivy.txt"
}
}
stage("Docker Push"){
steps{
script{
withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
sh "make push"
}
}
}
}
stage("Deploy to container"){
steps{
sh "docker run -d --name dotnet -p 5000:5000 writetoritika/dotnet-monitoring:latest"
}
}
stage('Deploy to k8s'){
steps{
dir('K8S') {
withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8s', namespace: '', restrictKubeConfigAccess: false, serverUrl: '') {
sh 'kubectl apply -f deployment.yaml'
}
}
}
}
}
}

External image reference Source image

[!Note] Join Our Telegram Community || Follow me for more DevOps Content

Use the guide first.

The full learning flow stays on this page. Open GitHub only when a step asks you to inspect code, fork the lab, or download source assets.