Learning state
Track this guide
Saved in this browser only. No account required.
On this page
DevOps Cheat Sheets Collection
Quick Reference Cards for All Master Classes
Essential commands and patterns at your fingertips
Docker Cheat Sheet
# Images
docker pull nginx
docker build -t myapp:v1 .
docker images
docker rmi image-id
# Containers
docker run -d -p 80:80 nginx
docker ps
docker stop container-id
docker rm container-id
docker logs container-id
docker exec -it container-id bash
# Cleanup
docker system prune -a
# Compose
docker-compose up -d
docker-compose down
docker-compose logs -f
Kubernetes Cheat Sheet
# Pods
kubectl get pods
kubectl describe pod pod-name
kubectl logs pod-name
kubectl exec -it pod-name -- bash
kubectl delete pod pod-name
# Deployments
kubectl create deployment nginx --image=nginx
kubectl scale deployment nginx --replicas=3
kubectl rollout status deployment/nginx
kubectl rollout undo deployment/nginx
# Services
kubectl expose deployment nginx --port=80 --type=LoadBalancer
kubectl get svc
# Namespaces
kubectl get ns
kubectl create ns production
kubectl config set-context --current --namespace=production
# Config
kubectl apply -f deployment.yaml
kubectl get all
kubectl describe deployment nginx
Git Cheat Sheet
# Setup
git config --global user.name "Name"
git config --global user.email "email@example.com"
# Basic
git init
git clone url
git status
git add .
git commit -m "message"
git push
git pull
# Branching
git branch
git branch feature
git checkout feature
git switch -c feature
git merge feature
git branch -d feature
# Undo
git reset --soft HEAD~1
git reset --hard HEAD~1
git revert commit-hash
# Remote
git remote -v
git remote add origin url
git push -u origin main
Terraform Cheat Sheet
# Init
terraform init
terraform init -upgrade
# Plan & Apply
terraform plan
terraform plan -out=tfplan
terraform apply
terraform apply tfplan
terraform apply -auto-approve
# Destroy
terraform destroy
terraform destroy -target=resource
# State
terraform state list
terraform state show resource
terraform state rm resource
# Format & Validate
terraform fmt -recursive
terraform validate
# Workspaces
terraform workspace list
terraform workspace new prod
terraform workspace select prod
Ansible Cheat Sheet
# Ad-hoc
ansible all -m ping
ansible all -m shell -a "uptime"
ansible webservers -m apt -a "name=nginx state=present" --become
# Playbooks
ansible-playbook playbook.yml
ansible-playbook playbook.yml --check
ansible-playbook playbook.yml --tags "config"
ansible-playbook playbook.yml --limit webservers
# Inventory
ansible-inventory --list
ansible-inventory --graph
# Vault
ansible-vault create secrets.yml
ansible-vault edit secrets.yml
ansible-vault encrypt file.yml
ansible-vault decrypt file.yml
Prometheus PromQL Cheat Sheet
# Rate
rate(http_requests_total[5m])
# Sum
sum(rate(http_requests_total[5m])) by (endpoint)
# Percentile
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))
# Availability
avg_over_time(up[24h])
# Top K
topk(5, sum(rate(http_requests_total[5m])) by (endpoint))
# Error rate
rate(http_requests_total{status=~"5.."}[5m])
AWS CLI Cheat Sheet
# EC2
aws ec2 describe-instances
aws ec2 start-instances --instance-ids i-xxx
aws ec2 stop-instances --instance-ids i-xxx
# S3
aws s3 ls
aws s3 cp file.txt s3://bucket/
aws s3 sync dir/ s3://bucket/dir/
# IAM
aws iam list-users
aws iam create-user --user-name john
aws iam create-access-key --user-name john
# EKS
aws eks list-clusters
aws eks update-kubeconfig --name cluster-name
Linux Commands Cheat Sheet
# Files
ls -la
cd /path
pwd
mkdir -p dir
rm -rf dir
cp source dest
mv old new
find . -name "*.txt"
grep "pattern" file
# Permissions
chmod 755 file
chown user:group file
umask 022
# Processes
ps aux
top
htop
kill pid
killall process
# System
df -h
du -sh *
free -h
uptime
systemctl status service
journalctl -u service -f
# Network
ip addr
ss -tulpn
ping host
curl url
wget url
Shell Scripting Cheat Sheet
# Variables
NAME="value"
echo $NAME
echo ${NAME}
# Conditionals
if [ condition ]; then
echo "true"
fi
# Loops
for i in {1..10}; do
echo $i
done
while [ condition ]; do
echo "loop"
done
# Functions
function name() {
echo "Hello $1"
}
# Arrays
ARR=("a" "b" "c")
echo ${ARR[0]}
echo ${ARR[@]}
# Special vars
$0 # Script name
$1 # First argument
$# # Number of arguments
$@ # All arguments
$? # Exit status
$$ # Process ID
Python DevOps Cheat Sheet
# File operations
from pathlib import Path
Path('file.txt').read_text()
Path('file.txt').write_text('content')
# Run commands
import subprocess
result = subprocess.run(['ls', '-la'], capture_output=True, text=True)
# AWS boto3
import boto3
s3 = boto3.client('s3')
s3.list_buckets()
s3.upload_file('local.txt', 'bucket', 'remote.txt')
# Kubernetes
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
v1.list_namespaced_pod('default')
# HTTP requests
import requests
response = requests.get('https://api.example.com')
data = response.json()
Database Cheat Sheet
PostgreSQL
-- Connect
psql -U user -d database
-- Databases
CREATE DATABASE mydb;
\l
\c mydb
-- Tables
CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(50));
\dt
\d users
-- Queries
SELECT * FROM users;
INSERT INTO users (name) VALUES ('John');
UPDATE users SET name = 'Jane' WHERE id = 1;
DELETE FROM users WHERE id = 1;
MongoDB
// Databases
show dbs
use mydb
// Collections
db.users.insertOne({name: "John"})
db.users.find()
db.users.updateOne({name: "John"}, {$set: {age: 30}})
db.users.deleteOne({name: "John"})
// Indexes
db.users.createIndex({name: 1})
Redis
# Strings
SET key "value"
GET key
DEL key
# Hashes
HSET user:1 name "John"
HGET user:1 name
HGETALL user:1
# Lists
LPUSH mylist "item"
LRANGE mylist 0 -1
🎓 DevOps Cheat Sheets Collection Complete