0% found this document useful (0 votes)
54 views19 pages

DevOps Materclass

Uploaded by

aatanda99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views19 pages

DevOps Materclass

Uploaded by

aatanda99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DevOps Masterclass

Class 1: Introduction to DevOps

What is DevOps?

DevOps is a combination of "Development" and "Operations," designed to bridge the gap


between software developers and IT operations teams. It focuses on improving collaboration,
automating processes, and delivering software faster and more reliably.

DevOps Principles and Culture

●​ Collaboration & Communication: DevOps removes silos between teams, fostering better
collaboration.
●​ Automation: Automating repetitive tasks increases efficiency and reduces errors.
●​ Continuous Integration & Continuous Deployment (CI/CD): Developers integrate and
deploy code frequently, reducing issues in production.
●​ Infrastructure as Code (IaC): Managing infrastructure using code for consistency and
scalability.
●​ Monitoring and Feedback: Ensuring applications run smoothly through real-time
monitoring and logging.
Img.1.1 CI/CD pipelines

History and Evolution of DevOps

DevOps emerged from the need to address the inefficiencies in traditional software
development and IT operations. It evolved from practices like Agile, Lean, and Continuous
Delivery.

study history: https://www.atlassian.com/devops/what-is-devops/history-of-devops


Img 1.2 Devops lifecycle

Key DevOps Practices

●​ CI/CD: Ensuring faster and reliable software releases.


●​ IaC: Automating infrastructure provisioning.
●​ Monitoring & Logging: Tracking system performance and identifying issues.

Study link: https://codefresh.io/learn/ci-cd/11-ci-cd-best-practices-for-devops-success/

Basic Linux Commands for DevOps

●​ ls - Lists directory contents


●​ cd - Changes directories
●​ pwd - Prints the current working directory
●​ mkdir - Creates a directory
●​ rm - Deletes files/directories
●​ chmod - Changes file permissions

Study Linux: https://www.coursera.org/articles/how-to-learn-linux


Networking Basics for DevOps

●​ IP Addressing & DNS: Understanding how computers communicate.


●​ Firewalls: Managing security between systems.
●​ SSH (Secure Shell): Accessing remote systems securely.

Study Networking:
https://www.linkedin.com/pulse/basic-networking-concepts-devops-engineer-daniel-gurus-ap
vhc/

Class 2: Version Control with Git

What is Version Control?

Version control is a system that helps track changes to files over time, allowing teams to
collaborate efficiently.

Git Overview

Git is a distributed version control system that allows developers to track changes, collaborate,
and revert to previous versions.

Basic Git Commands

●​ git init - Initializes a new Git repository.


●​ git clone {repo-url} - Clones an existing repository
●​ git add {file} - Stages a file for commit.
●​ git commit -m "message" - Saves changes to the repository.
●​ git push - Uploads commits to a remote repository.
●​ git pull - Fetches and merges updates from a remote repository.

Basics of git: git - the simple guide - no deep shit!

Branching & Merging

●​ Branches allow multiple people to work on different features independently.


●​ Merging integrates changes from different branches.
https://www.geeksforgeeks.org/branching-strategies-in-git/

GitHub & Collaboration

Introduction to GitHub

GitHub is a web-based platform for hosting Git repositories, enabling collaboration among
developers.

Creating a GitHub Repository

1.​ Go to GitHub and sign in.


2.​ Click on "New Repository."
3.​ Enter a repository name and select "Public" or "Private."
4.​ Initialize with a README.md (optional).
5.​ Click "Create Repository."

Link:https://docs.github.com/en/repositories/creating-and-managing-repositories/quickstart-fo
r-repositories

GitHub Collaboration Workflows

●​ Forking & Pull Requests: Copying a repository, making changes, and requesting a
merge.
●​ Issues & Discussions: Reporting bugs and discussing enhancements.
●​ CI/CD with GitHub Actions: Automating builds and deployments.

Link: https://www.geeksforgeeks.org/git-workflows-with-open-source-collaboration/

Practical Exercise

●​ Create a GitHub repository.


●​ Clone it locally and make some changes.
●​ Commit and push changes.
●​ Create a new branch, make changes, and merge it back.
Class 3: Scripting and Automation

Introduction to Automation in DevOps

Automation is at the core of DevOps. It enables faster and more reliable software development,
testing, deployment, and infrastructure management. DevOps engineers automate repetitive
tasks like:

●​ Software builds and deployments


●​ Infrastructure provisioning
●​ Configuration management
●​ Monitoring and alerts
●​ Security and compliance

Why is automation important?

●​ Speed – Reduces manual intervention, increasing productivity


●​ Consistency – Eliminates human errors in repetitive tasks
●​ Scalability – Makes it easier to manage large-scale systems
●​ Cost Efficiency – Saves time and reduces operational expenses

Bash Scripting for Automation

What is Bash?​
Bash (Bourne Again Shell) is a command-line interpreter and scripting language for Unix/Linux.
It helps automate system administration and DevOps tasks.

Basic Bash Commands

Command Description

ls List files and directories

pwd Print current directory

mkdir folder_name Create a new directory


rm file.txt Remove a file

chmod +x script.sh Make a script executable

cat file.txt Display file contents

echo "Hello World" Print text to terminal

Writing a Simple Bash Script

A Bash script is a file containing a series of shell commands.

1.​ Create a file script.sh

#!/bin/bash
echo "Hello, DevOps!"
mkdir devops_folder
cd devops_folder
echo "This is a DevOps script" > info.txt
cat info.txt

2.​ Give execute permission and run it:

chmod +x script.sh
./script.sh

Conditional Statements in Bash

#!/bin/bash
read -p "Enter your name: " name
if [ "$name" == "DevOps" ]; then
echo "Welcome, DevOps Engineer!"
else
echo "Hello, $name!"
fi

Looping in Bash

#!/bin/bash
for i in {1..5}
do
echo "Iteration $i"
done

Learn Bash:

●​ Bash Scripting Guide:


https://www.freecodecamp.org/news/bash-scripting-tutorial-linux-shell-script-and-com
mand-line-for-beginners/
●​ Shell Scripting Tutorial: https://www.shellscript.sh/

Python for DevOps Automation

Why Python?

●​ Easy to learn and powerful


●​ Works across platforms (Linux, Windows, Mac)
●​ Great for scripting, infrastructure automation, and CI/CD pipelines

Installing Python

For Windows: Download Python

https://phoenixnap.com/kb/how-to-install-python-3-windows

Writing a Simple Python Script


# hello.py
print("Hello, DevOps!")

Run it:

python3 hello.py

Automating File Handling with Python

import os
# Create a directory
os.makedirs("devops_folder", exist_ok=True)

# Create and write to a file


with open("devops_folder/info.txt", "w") as f:
f.write("This is a DevOps automation script.")

print("Automation complete!")

Using Python for API Automation

import requests
response = requests.get("https://api.github.com")
print(response.json())

Learn Python for DevOps:

●​ Python for DevOps


●​ Automate the Boring Stuff with Python

3.​ Automating Cloud Infrastructure (AWS CLI & Boto3)

AWS CLI (Command Line Interface)

AWS CLI allows automation of AWS services using command-line commands.

1.​ Install AWS CLI


sudo apt install awscli -y

2.​ Configure AWS CLI

aws configure

It will ask for:

●​ AWS Access Key


●​ AWS Secret Key
●​ Default region (e.g., eu-west-2)
●​ Output format (default is json)

3.​ Create an S3 Bucket using AWS CLI

aws s3 mb s3://ade-devops-bucket

Learn AWS CLI:

●​ AWS CLI Documentation

4.​ Infrastructure as Code (IaC) with Terraform (Example)

Terraform allows defining infrastructure as code.

Example:

provider "aws" {

region = "eu-west-2"

resource "aws_s3_bucket" "example" {

bucket = "my-devops-bucket"

}
Then write these in bash:

terraform init

terraform apply

More details in Class 4!

Practical Exercises (Hands-On)

Exercise 1: Write a Bash Script

Create a script that:

●​ Creates a directory
●​ Writes text to a file
●​ Displays the content of the file

Exercise 2: Automate with Python

Write a Python script that:

●​ Creates a folder
●​ Writes "Hello, DevOps!" to a file
●​ Reads and prints the file content

Next Class: Terraform & Infrastructure as Code (IaC)

Further Reading & Learning Resources​


🔗 Python for DevOps:​
🔗 AWS CLI Documentation​
🔗 Terraform Getting Started:
https://k21academy.com/terraform-iac/terraform-beginners-guide/

Study more on CI/CD: https://www.atlassian.com/continuous-delivery


Why CI/CD Matters in DevOps

1.​ Faster Releases – Automates the build, test, and deployment processes.
2.​ Higher Code Quality – Ensures code is always tested before deployment.
3.​ Reduced Errors – Detects and fixes bugs early in the development cycle.
4.​ Better Collaboration – Allows teams to work simultaneously on different features.

CI/CD Pipeline Workflow:​

CI/CD Pipeline Components

A CI/CD pipeline consists of several automated steps that take code from development to
production.

1.​ Source Code Management (SCM) – Developers push code to a repository (Git,
GitHub, GitLab, Bitbucket).
2.​ Build Stage – The code is compiled and dependencies are installed.
3.​ Testing Stage – Unit tests, integration tests, and security checks are performed.
4.​ Artifact Storage – Build outputs are stored in artifact repositories (e.g., JFrog
Artifactory, Nexus, AWS S3).
5.​ Deployment Stage – Applications are deployed to testing, staging, or production
environments.
6.​ Monitoring & Feedback – Tools like Prometheus, Grafana, and ELK Stack monitor
system performance.

Learn More About CI/CD Pipelines: Codefresh's CI/CD Best Practices

CI/CD Tools Overview

Various tools help automate different stages of the CI/CD pipeline.

CI/CD Tools Comparison

Category Tools
Source Code Management Git, GitHub, GitLab, Bitbucket

CI/CD Automation Jenkins, GitHub Actions, GitLab CI/CD, CircleCI, Travis CI

Build & Artifact Management Maven, Gradle, Docker, JFrog Artifactory

Testing Selenium, JUnit, PyTest, SonarQube

Deployment Kubernetes, Helm, AWS CodeDeploy, ArgoCD

Monitoring Prometheus, Grafana, ELK Stack

Setting Up a Basic CI/CD Pipeline with GitHub Actions

GitHub Actions is an automation tool that enables CI/CD workflows directly in GitHub
repositories.

Steps to Create a CI/CD Pipeline with GitHub Actions

1.​ Create a GitHub Repository


2.​ Add a .github/workflows/ci-cd-pipeline.yml file
3.​ Define the Workflow YAML file

Example GitHub Actions CI/CD Workflow:

name: CI/CD Pipeline

on:

push:

branches:
- main

pull_request:

branches:

- main

jobs:

build:

runs-on: ubuntu-latest

steps:

- name: Checkout Code

uses: actions/checkout@v2

- name: Set up Node.js

uses: actions/setup-node@v3

with:

node-version: '16'

- name: Install Dependencies

run: npm install

- name: Run Tests

run: npm test


- name: Build Application

run: npm run build

Learn more about GitHub Actions: GitHub Actions Documentation

Jenkins CI/CD Pipeline Example

Jenkins is one of the most popular CI/CD tools. Below is an example of how to create a
Jenkins pipeline.

Steps to Set Up Jenkins CI/CD Pipeline:

1.​ Install Jenkins and required plugins (Pipeline, Git, Docker).


2.​ Create a new Pipeline Job in Jenkins.
3.​ Define a Jenkinsfile in your repository.

Example Jenkinsfile for CI/CD:

groovy file:

pipeline {

agent any

stages {

stage('Checkout Code') {

steps {

git 'https://github.com/your-repo.git'

}
stage('Build') {

steps {

sh 'mvn clean install'

stage('Test') {

steps {

sh 'mvn test'

stage('Deploy') {

steps {

sh 'scp target/app.jar user@server:/opt/app/'

sh 'ssh user@server "systemctl restart app.service"'

Learn more about Jenkins Pipelines: Jenkins Pipeline Syntax


Containerization in CI/CD

CI/CD pipelines often use Docker and Kubernetes to manage and deploy applications in a
consistent and scalable way.

Dockerizing an Application for CI/CD

1.​ Create a Dockerfile

The filename is dockerfile

FROM node:16

WORKDIR /app

COPY . .

RUN npm install

CMD ["npm", "start"]

2.​ Build and Push to Docker Hub

docker build -t username/app-name .

docker push username/app-name

Deploying Applications with Kubernetes in CI/CD

For containerized deployments, CI/CD pipelines integrate with Kubernetes using tools like
ArgoCD, Helm, or Kustomize.

Example Kubernetes Deployment YAML:

apiVersion: apps/v1
kind: Deployment

metadata:

name: my-app

spec:

replicas: 3

selector:

matchLabels:

app: my-app

template:

metadata:

labels:

app: my-app

spec:

containers:

- name: my-app

image: username/app-name:latest

ports:

- containerPort: 80

Learn more about Kubernetes Deployments:


https://www.datacamp.com/tutorial/kubernetes

Practical Exercise: Build a CI/CD Pipeline with Jenkins and Docker


Steps:

1.​ Install Jenkins, Docker, and Git on your server/machine


2.​ Create a GitHub repository for your application.
3.​ Write a Jenkinsfile to define the pipeline.
4.​ Configure Docker to containerize an application.

Complete CI/CD Pipeline Setup Guide: DevOps with AWS

https://www.linkedin.com/pulse/how-build-scalable-cicd-pipeline-comprehensive-guide-abhis
hek-rana-ktzkc

●​ CI/CD is critical for DevOps success.


●​ Automating deployments reduces manual errors.
●​ Monitoring and security should be integrated into CI/CD pipelines.
●​ Continuous learning is necessary as CI/CD tools evolve.

You might also like