Devops Notes

What is DevOps?

DevOps = Development + Operations

  • Bridge the gap between developers (who write code) and operations (who deploy and maintain apps).

Common DevOps Tools:

CategoryTools
Source controlGit, GitHub, GitLab
CI/CD (automation)Jenkins, GitHub Actions, CircleCI
Configuration managementAnsible, Puppet, Chef
ContainerizationDocker
OrchestrationKubernetes
MonitoringPrometheus, Grafana

DevOps is about how you build, deploy, and manage applications efficiently.

Git :

rohith@rohith-ROG-Strix-G513RC-G513RC:~$ git --version
git version 2.43.0
rohith@rohith-ROG-Strix-G513RC-G513RC:~$ git config --global user.name "rohith" (To assign your name)
rohith@rohith-ROG-Strix-G513RC-G513RC:~$ git config --global user.email "rohithvishva2005@gmail.com" (Email)

Git Branch — a parallel version of the main code

Commands :

Initialize project

git init
git add .
git commit -m "Initial commit"

Create remote and push

git branch -M main
git remote add origin https://github.com/username/repo.git
git push -u origin main

Create new feature branch

git checkout -b feature/login

Work on feature

git add .
git commit -m "Add login feature"

Merge back to main

git checkout main
git pull
git merge feature/login
git push

Github actions :

the above image explains a code in local pc is sent to github and server is pulling it , and composed in a docked file now , when we change any code in local pc , we need to follow these steps manually , so we use CI/CD pipelines to avoid this manual steps

CI/CD - giving a script which can repeat in every push

these script is given in .yaml file which include

  • whenever there is a push
  • SSH into my server
  • CD / home / app
  • git pull
  • docker compose file up -d

and we write docker file — Dockerfile

and in docker-compose.yml

and after this u need to have a server to access and get SSH code ref (YT)- https://youtu.be/y7S2oSjJ8PA?si=SKbKBvwkB5k9rwBN

now we are doing github actions : automation of pull to server and build docker image

in root create folder named .github inside that crerate folder named workflow and in that a file named deploy.yaml

deploy.yaml

Linux :


1. Introduction to Linux in DevOps

Why Linux is important

Linux is the backbone of modern DevOps because:

  • Most DevOps tools are built for Linux:
    • Docker
    • Kubernetes
    • Git
    • Jenkins
    • Terraform
  • Cloud servers (AWS, Azure, GCP) primarily run Linux
  • High stability and uptime
  • Better security model (permissions & isolation)
  • Excellent performance and resource efficiency
  • Open source and highly customizable

Accessing Linux on Windows using WSL (Windows Subsystem for Linux)

Install Ubuntu on Windows:

wsl --install

Check installed distributions:

wsl --list --verbose

Start Linux shell:

wsl

Now you can use Linux terminal directly on Windows.


2. Navigating the Linux File System

Basic navigation commands

CommandPurpose
pwdShow current directory
lsList files
ls -lDetailed file list
ls -aInclude hidden files
cd folderMove into folder
cd ..Go back one level
cd ~Go to home directory
cd /Go to root directory

File & directory management

CommandPurpose
touch file.txtCreate empty file
mkdir folderCreate folder
rm file.txtDelete file
rm -r folderDelete folder recursively
cp file1 file2Copy file
mv file newLocation/Move / rename file

Examples:

touch app.js
mkdir server
mv app.js server/
rm app.js

3. Searching Files

Using find

Search for a file by name:

find ~/Desktop -name "file1.txt"

Using grep

Search inside files for text:

grep "hello" file1.txt

Recursive search:

grep -r "password" .

4. Shell Scripting Basics

What is shell scripting?

  • A shell script is a file containing Linux commands
  • Used to automate tasks
  • Runs sequentially
  • Saves time and avoids human errors

Basic script structure

#!/bin/bash
echo "Hello World"

#!/bin/bash → tells system to use Bash shell


Creating & running a script

nano script.sh
chmod +x script.sh
./script.sh

Explanation:

  • nano script.sh → create file
  • chmod +x → make executable
  • ./script.sh → run script

5. Variables & Conditions

Variables

#!/bin/bash
name="Alice"
echo "Hello $name"

Rules:

  • No spaces around =
  • Access using $variable

If condition example

#!/bin/bash
num=5

if [ $num -gt 3 ]; then
  echo "Number > 3"
else
  echo "Number <= 3"
fi

Comparison operators:

OperatorMeaning
-gtgreater than
-ltless than
-eqequal
-nenot equal

6. Applying Shell Scripts in MERN Projects

Use case: Start backend and frontend together

Instead of opening two terminals, automate using a script.

Create file:

start.sh

Script content:

#!/bin/bash

echo "Starting MERN application..."

# Start backend
cd server || exit
npm start &

# Start frontend
cd ../client || exit
npm run dev

Make executable:

chmod +x start.sh

Run:

./start.sh

Docker :

1. Traditional Problem

Normally, apps run differently on different machines because of:

  • Different OS versions
  • Missing dependencies
  • Configuration conflicts

For example, something that works on your laptop might fail on a server.

2. What Docker Does

Docker packages your app + all its dependencies (like libraries, configs, OS tools) into a container.

This container can run anywhere, no matter the environment.

3. Key Concepts

TermDescription
ImageA blueprint for your container (like a snapshot of your app + environment). Docker Images are - Lightweight , - Standalone , Executable Package
ContainerA running instance of an image. Each container is isolated but lightweight. Downloading packages running commands happens here
Docker fileA script that defines how to build an image (commands like FROM, RUN, COPY).
Docker HubA cloud registry to store and share images (like GitHub for Docker).
Docker EngineThe core service that builds and runs containers.
Docker VolumeA Docker volume is a permanent storage mechanism that lets data survive even after a container is deleted or recreated.
Docker NetworkA Docker network connects containers together — allowing them to communicate securely and easily.
By default, containers are isolated — they can’t talk to each other or the outside world unless connected to a network.

-imp

-normal


1.Basic Docker Commands

CommandDescription
docker --versionCheck Docker version
docker infoShow system-wide information
docker helpList all Docker commands
docker <command> --helpHelp for a specific command

2.Docker Images

CommandDescription
docker imagesList all images
docker pull <image>Download an image from Docker Hub
docker search <name>Search images on Docker Hub
docker rmi <image>Remove an image
docker rmi $(docker images -q)Remove all images
docker inspect <image>View detailed info about an image
docker history <image>Show image build history
docker tag <source> <target>Tag an image
docker save -o <file.tar> <image>Save image to a tar file
docker load -i <file.tar>Load image from a tar file
docker run -d <image_name>detach mode, detaches and run behind the terminal

3.Docker Containers

CommandDescription
docker psList running containers
docker ps -aList all containers (including stopped)
docker run <image>Run a container
docker run -it <image> bashRun container in interactive terminal
docker start <containerID>Start a stopped container by id u can access a particular container
docker stop <container>Stop a running container
docker restart <container>Restart a container
docker rm <container>Remove a stopped container
docker rm -f <container>Force remove running container
docker logs <container>View container logs
docker exec -it <container> bashOpen terminal inside a container
docker inspect <container>Get detailed info about container
docker top <container>Show processes running inside a container
docker statsShow container resource usage
docker rename <old> <new>Rename a container
docker exec -it <container_id> /bin/bash

4.Docker Volumes (Data Storage)

CommandDescription
docker volume create <name>Create a volume
docker volume lsList all volumes
docker volume inspect <name>Show volume details
docker volume rm <name>Remove a volume
docker volume pruneRemove all unused volumes
docker run -v <volume>:/path/in/container <image>Attach volume to container

5.Docker Networks

CommandDescription
docker network lsList networks
docker network create <name>Create a network
docker network inspect <name>Inspect a network
docker network connect <network> <container>Connect container to network
docker network disconnect <network> <container>Disconnect container
docker network rm <name>Remove a network
docker network pruneRemove all unused networks

6.Docker Compose

CommandDescription
docker compose upStart services defined in docker-compose.yml
docker compose up -dStart services in background
docker compose downStop and remove containers, networks, volumes
docker compose psList running services
docker compose logsView service logs
docker compose restartRestart services
docker compose exec <service> bashRun a command in a service container

7.Docker System Maintenance

CommandDescription
docker system dfShow disk usage
docker system pruneRemove all unused data (containers, networks, etc.)
docker system prune -aRemove all unused images and containers
docker builder pruneRemove unused build cache

8.Docker Build

CommandDescription
docker build -t <name> .Build image from Dockerfile
docker build -f <Dockerfile> -t <name> .Specify a custom Dockerfile
docker commit <container> <image>Create image from container changes
docker history <image>View image layer history

9.Docker Login / Registry

CommandDescription
docker loginLog in to Docker Hub
docker logoutLog out from Docker Hub
docker push <image>Push image to Docker Hub
docker pull <image>Pull image from Docker Hub

10.Docker Permissions (Non-root setup)

To run Docker without sudo:

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

Then verify:

docker ps


Bonus: Useful One-Liners

CommandDescription
docker stop $(docker ps -q)Stop all containers
docker rm $(docker ps -aq)Remove all containers
docker rmi $(docker images -q)Remove all images
docker volume rm $(docker volume ls -q)Remove all volumes
docker network rm $(docker network ls -q)Remove all networks

// IMP

docker run <image>

docker run -d <image> {runs behind , will not load in terminal}

docker run —name my-container <image>

docker run -v $(pwd):<image> {pwd - present working directory }

docker run -it <image> sh {to intract with container



docker ps

docker ps -a

docker logs <container>

docker attach <container>

docker stop <container>

docker kill <container>

docker stop $(docker ps -a)

docker start <container>

docker rm <cont>

docker cp <cont> :/path/


SymbolMeaningExampleDescription
.current directory./file.jsRefers to the file or folder in the same folder as the current file.
..parent directory../config.jsGoes one level up from the current folder.
../..two levels up../../env/.envGoes two levels up the directory tree.
/root (depends on context)/home/user/projectIn absolute paths — refers to the root directory.
./same as . but used for clarity./index.jsExplicitly tells code “this file is in the current directory.”

CI: → Continuous Integration


It’s the DevOps practice of automatically building, testing, and integrating code changes whenever developers push updates to a shared repository (like GitHub, GitLab, or Bitbucket).

common problems : you dont find bugs until days or weeks

merge conflict can pile up

one change can break multiple other changes

tier :

P0 > P1 > P2 > P3 > P4

P0 → main code , p4 , p3 test codes

// 1 → main branch → devbranch (copy of main) → all other developers branch (Dev1 , Dev2 , Dev3) {they push to dev and if everything is good update main}

Developer → Pushes code → GitHub triggers CI pipeline →
CI server builds + runs tests → Reports success or failure

CI vs CD — Full Explanation

CI/CD is a DevOps practice that automates integration, testing, delivery, and deployment of software.

It has 3 major stages:

  1. CI – Continuous Integration
  1. CD – Continuous Delivery
  1. CD – Continuous Deployment

    (yes, the “CD” has two meanings)


1. Continuous Integration (CI)

Definition

CI is the practice of automatically building and testing code every time a developer pushes changes.

Goal

Catch bugs early → prevent broken code from entering the main branch.

What CI includes

  • Installing dependencies
  • Running tests (unit/integration)
  • Running ESLint checks
  • Running Prettier checks
  • Running type checks (TypeScript)
  • Building the project
  • Verifying code quality

CI Tools

  • GitHub Actions
  • GitLab CI
  • Jenkins
  • CircleCI
  • TravisCI
  • Azure DevOps

Main Use Cases

  • Ensure code compiles successfully
  • Detect bugs automatically
  • Prevent bad code from being merged
  • Enforce coding standards (lint)
  • Run automated tests before merging
  • Speed up team collaboration

2. Continuous Delivery (CD)

Definition

Continuous Delivery takes the output of CI and prepares it for deployment, but requires manual approval before production.

Goal

Keep the app always ready to deploy with one click.

What Continuous Delivery includes

  • Packaging the application
  • Creating Docker images
  • Uploading artifacts (zip, jars, dist folder)
  • Pushing Docker images to registry (Docker Hub, AWS ECR)
  • Running staging environment builds
  • Deployment manual trigger required

CD Tools

  • GitHub Actions
  • GitLab CD
  • Jenkins (Pipeline)
  • ArgoCD
  • Spinnaker

Main Use Cases

  • Deploy to staging environment
  • Allow QA to test before release
  • Ensure release builds are always ready
  • Human-approved deployment to production

3. Continuous Deployment (CD)

Definition

Continuous Deployment automatically deploys code to production after all tests/validations pass.

No manual approval. Fully automatic.

Goal

Fastest delivery of new features → automation end-to-end.

What Continuous Deployment includes

  • Auto deploy to production servers
  • Auto push Docker containers to Kubernetes
  • Auto scaling & rolling updates
  • Monitoring after deployment

Tools for Continuous Deployment

  • Kubernetes
  • ArgoCD
  • Spinnaker
  • GitHub Actions (can be used)
  • Amazon CodePipeline

Main Use Cases

  • High-frequency deployments
  • SaaS platforms (e.g., Netflix, Facebook)
  • Fully automated DevOps pipelines
  • Teams that deploy multiple times per day

Summary Table — CI vs CD vs CD

Feature / AspectCI (Integration)CD (Delivery)CD (Deployment)
Runs on push
Automated testing
Automated builds
Creates deployable artifacts
Requires manual approval
Auto-deploy to production
Uses DockerOptional
Uses KubernetesOptional
Main goalCode qualityReady-to-deploy releasesAuto deploy to production
Difficulty levelEasyMediumHard

Where does Docker fit?

Docker is mainly used in:

Continuous Delivery → Packaging

  • Build Docker image
  • Push to registry

Continuous Deployment → Deployment

  • Deploy Docker image to server/Kubernetes

Docker is NOT CI-only.

But CI can also build Docker images for testing.


Practical Example in a MERN Project

● CI Tasks

  • npm install
  • npm run lint
  • npm test
  • npm run build
  • Verify backend routes

● Continuous Delivery Tasks

  • docker build
  • docker push
  • Prepare release artifacts
  • Deploy to staging serverT

● Continuous Deployment Tasks

  • Automatically deploy Docker images
  • Rollout update in Kubernetes
  • Auto-scale backend pods

Simple Explanation

CI automates code testing and integration.

CD (Delivery) automates preparing builds for release.

CD (Deployment) automates releasing the app to production.

CI/CD {Jenkins & GitLabs}:

Jenkins :

  • open-source automation sever
  • orchestrate software dev
  • jenkins looks for changes in code and triger test stages , builds and even pushes code
  • Build : here we check code complaints , executable application
  • Test : unit test , integration testing , end to end testing
  • Deploy stage : pushing the application to cloud environment
  • jenkins can easily integrated with any tool like , version control , cloud plotforms {AWS , Azure} , testing frameworks , notification tools
  • Monitors source code repositories and triggers pipelines on events (commit, PR, schedule, webhook).
  • Executes pipelines consisting of stages such as:

Build stage

  • Compile code
  • Run static code analysis (code quality / linting)
  • Produce artifacts (JAR, Docker image, binary, etc.)

Test stage

  • Unit tests
  • Integration tests
  • End-to-end (E2E) tests

Deploy stage

  • Deploys applications to environments:
    • Cloud (AWS, Azure, GCP)
    • On-prem servers
    • Kubernetes / Docker platforms
  • Integrates easily with:
    • Version control (GitHub, GitLab, Bitbucket)
    • Cloud providers (AWS, Azure, GCP)
    • Build tools (Maven, Gradle, npm)
    • Testing frameworks (JUnit, Selenium, Cypress)
    • Notification tools (Slack, Email, Teams)

GitLabs :

  • while Jenkins is automation plotform, gitlabs provides all in one plotform like CI/CD
  • here we define ci in the repo inside yaml file{gitlab-ci,yaml}

why should i use jenkins with gitlab , when gitlab provides all features ?

Existing Jenkins infrastructure

Many organizations already have:

  • Large, complex Jenkins pipelines
  • Custom plugins
  • Enterprise integrations
  • Legacy workflows

Migrating everything to GitLab CI is:

  • Risky
  • Time-consuming
  • Expensive

So GitLab is used only as source control,and Jenkins handles CI/CD.


Advanced customization

Jenkins offers:

  • Extremely flexible pipelines (Groovy DSL)
  • Thousands of plugins
  • Custom agents & infrastructure control

Some enterprises need this level of control.


GitLab → Jenkins triggering

GitLab can trigger Jenkins jobs using:

  • Webhooks
  • Jenkins API
  • GitLab CI jobs calling Jenkins

So:

GitLab manages code → Jenkins runs pipelines

Diffrence btw github actions and gitLabs

FeatureGitHub ActionsGitLab CI
Repo hostingGitHub onlyGitLab only
CI/CDYesYes
Issue trackingYesYes
Container registryLimitedBuilt-in
Security scanningBasicAdvanced built-in
DevOps lifecyclePartialComplete (end-to-end)
What is a Webhook?

A webhook is an HTTP callback mechanism.

It automatically sends a real-time HTTP request to another system when a specific event occurs.

In simple terms:

“Something happened → notify another system immediately.”

How it works (flow)

  1. An event occurs

    (e.g., git push, merge, payment success, issue created)

  1. The source system sends an HTTP POST request to a configured URL
  1. The target system receives it and executes an action
GitHub/GitLab → (Webhook HTTP POST) → Jenkins /Server / API

Ansible :

A open source automation tool used to config servers ,deploy apps and ,manage infra

Ansible is mainly used for:

  • Server setup (installing packages, configuring services)
  • Deploying applications
  • Managing cloud infrastructure
  • DevOps automation
  • CI/CD pipelines
  • Infrastructure as Code (IaC)

Example: yaml file

  • hosts: webservers
    become: yes
    tasks:
    • name: Install nginx
      apt:
      name: nginx
      state: present

then run : ansible-playbook install-nginx.yml