HxHippy

DevOps Engineer Cheat Sheet

CI/CD, automation, and infrastructure as code quick reference.

Last updated: 2025-01-15

DevOps Engineer Cheat Sheet

Essential commands for CI/CD, automation, and infrastructure as code.

Quick Reference

# Deploy workflow
git pull && docker-compose build && docker-compose up -d

# Infrastructure change
terraform plan && terraform apply

# Configuration push
ansible-playbook -i prod playbook.yml --check

Git Workflows

# Feature branch workflow
git checkout -b feature/new-feature
git add . && git commit -m "feat: add feature"
git push -u origin feature/new-feature

# Rebase and squash
git fetch origin
git rebase -i origin/main
git push --force-with-lease

# Cherry pick
git cherry-pick <commit-hash>

# Stash work
git stash push -m "WIP: description"
git stash pop

Terraform

# Initialize
terraform init
terraform init -upgrade

# Plan and apply
terraform plan -out=plan.tfplan
terraform apply plan.tfplan

# State management
terraform state list
terraform state show aws_instance.web
terraform state mv aws_instance.old aws_instance.new

# Workspaces
terraform workspace list
terraform workspace new staging
terraform workspace select production

# Import existing resource
terraform import aws_instance.web i-1234567890abcdef0

Ansible

# Run playbook
ansible-playbook -i inventory playbook.yml
ansible-playbook -i inventory playbook.yml --limit webservers
ansible-playbook -i inventory playbook.yml --tags "deploy"

# Dry run
ansible-playbook -i inventory playbook.yml --check --diff

# Ad-hoc commands
ansible all -i inventory -m ping
ansible webservers -i inventory -m shell -a "df -h"
ansible all -i inventory -m copy -a "src=file.txt dest=/tmp/"

# Vault
ansible-vault create secrets.yml
ansible-vault edit secrets.yml
ansible-playbook playbook.yml --ask-vault-pass

Docker & Compose

# Build and run
docker build -t myapp:latest .
docker-compose up -d --build

# Logs and debugging
docker-compose logs -f app
docker exec -it container_name bash

# Cleanup
docker system prune -a
docker volume prune

# Registry
docker login registry.example.com
docker push registry.example.com/myapp:v1.0

Kubernetes

# Apply manifests
kubectl apply -f deployment.yaml
kubectl apply -k overlays/production/

# Get resources
kubectl get pods -n namespace
kubectl get all -A
kubectl describe pod pod-name

# Logs and exec
kubectl logs -f pod-name
kubectl exec -it pod-name -- /bin/sh

# Rollout
kubectl rollout status deployment/app
kubectl rollout history deployment/app
kubectl rollout undo deployment/app

CI/CD Pipelines

GitHub Actions

# .github/workflows/deploy.yml
name: Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./deploy.sh

Jenkins Pipeline

pipeline {
  agent any
  stages {
    stage('Build') { steps { sh 'make build' } }
    stage('Test') { steps { sh 'make test' } }
    stage('Deploy') { steps { sh 'make deploy' } }
  }
}

Monitoring Commands

# Check endpoints
curl -s http://localhost:8080/health | jq .
curl -w "%{http_code}" -s -o /dev/null http://localhost:8080/

# Prometheus queries (via API)
curl 'http://prometheus:9090/api/v1/query?query=up'

# Logs (structured)
kubectl logs -l app=myapp --tail=100 | jq .

Common Patterns

Task Command
Blue-green deploy kubectl set image deployment/app
Canary release kubectl scale --replicas=1
Rollback kubectl rollout undo
Secret rotation kubectl create secret --dry-run
Config update kubectl rollout restart
intermediate DevOps Roles Updated 2025-01-15
  • devops
  • ci/cd
  • automation
  • terraform
  • ansible
  • jenkins