Introduction to DevOps
Learn the fundamentals of DevOps including CI/CD, Infrastructure as Code, containerization, and the DevOps lifecycle. Perfect for beginners starting their DevOps journey.
What is DevOps?
DevOps is a set of practices, tools, and cultural philosophies that automate and integrate the processes between software development and IT operations teams. The goal is to shorten the systems development lifecycle while delivering features, fixes, and updates frequently in close alignment with business objectives.
The term "DevOps" is a combination of "Development" and "Operations," representing the collaboration between these traditionally siloed teams. DevOps emphasizes communication, collaboration, integration, automation, and measurement of cooperation between software developers and other IT professionals.
Key Principles of DevOps
1. Continuous Integration (CI)
Continuous Integration is the practice of automatically integrating code changes from multiple contributors into a single software project. Developers frequently merge their code changes into a central repository, after which automated builds and tests are run.
2. Continuous Delivery/Deployment (CD)
Continuous Delivery ensures that code can be rapidly and safely deployed to production by delivering every change to a production-like environment through rigorous automated testing. Continuous Deployment takes this a step further by automatically releasing every change that passes all stages of your production pipeline.
3. Infrastructure as Code (IaC)
Infrastructure as Code is the managing and provisioning of infrastructure through code instead of through manual processes. With IaC, configuration files are created that contain your infrastructure specifications, which makes it easier to edit and distribute configurations.
DevOps Tools Ecosystem
Version Control
- Git - Distributed version control system
- GitHub/GitLab/Bitbucket - Git hosting platforms
CI/CD Tools
- Jenkins - Open-source automation server
- GitHub Actions - CI/CD built into GitHub
- GitLab CI - Integrated CI/CD with GitLab
- CircleCI - Cloud-based CI/CD platform
Containerization
- Docker - Container platform
- Kubernetes - Container orchestration
- Podman - Daemonless container engine
Configuration Management
- Ansible - Agentless automation
- Terraform - Infrastructure as Code
- Puppet/Chef - Configuration management
The DevOps Lifecycle
The DevOps lifecycle consists of eight phases representing the processes, capabilities, and tools needed for development (on the left side of the loop) and operations (on the right side of the loop). Throughout each phase, teams collaborate and communicate to maintain alignment, velocity, and quality.
- Plan - Define requirements and track work
- Code - Write and review code
- Build - Compile and create artifacts
- Test - Automated testing
- Release - Prepare for deployment
- Deploy - Push to production
- Operate - Manage infrastructure
- Monitor - Track performance and issues
Benefits of DevOps
- ๐ Faster Time to Market - Rapid delivery of features
- ๐ Continuous Improvement - Regular feedback loops
- ๐ก๏ธ Increased Reliability - Automated testing reduces errors
- ๐ Scalability - Infrastructure that grows with demand
- ๐ฅ Better Collaboration - Breaking down silos
- ๐ฐ Cost Efficiency - Automation reduces manual work
#!/bin/bash
# Simple CI script to run tests
echo "๐ Installing dependencies..."
pip install -r requirements.txt
echo "๐งช Running unit tests..."
python -m pytest tests/ -v
echo "๐ Running code coverage..."
python -m pytest --cov=src tests/
echo "โ
All tests passed!"
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Run tests
run: |
pytest tests/ -v --cov=src
- name: Build Docker image
run: |
docker build -t myapp:${{ github.sha }} .
- name: Deploy to staging
if: github.ref == 'refs/heads/develop'
run: |
echo "Deploying to staging..."
# main.tf - AWS EC2 Instance Configuration
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "web_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
Environment = "Production"
ManagedBy = "Terraform"
}
user_data = <<-EOF
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
EOF
}
output "public_ip" {
value = aws_instance.web_server.public_ip
}
version: '3.8'
services:
web:
build: ./app
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgres://db:5432/myapp
- REDIS_URL=redis://cache:6379
depends_on:
- db
- cache
restart: always
db:
image: postgres:15
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=myapp
- POSTGRES_PASSWORD=secret
cache:
image: redis:7-alpine
ports:
- "6379:6379"
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- web
volumes:
postgres_data:
Test Your Knowledge
Answer these questions to check your understanding