A single reference page for the tools DevOps engineers reach for daily: Terraform, Kubernetes, kubectl, K3s, Docker, Docker Compose, Helm, Ansible, Git, and CI/CD. Bookmark it, search it, and use it when you need the command or YAML skeleton fast.
Terraform Cheat Sheet
Terraform manages infrastructure through declarative HCL files and a state file that tracks what exists in the real world.
Production tip: Always run terraform plan in CI before merge. Store state remotely (S3 + DynamoDB lock, Terraform Cloud, or equivalent). Never commit .tfstate or secrets in .tfvars.
kubectl Cheat Sheet
kubectl is the CLI for Kubernetes. Install it separately or use it through K3s (k3s kubectl).
Context and configuration
Command
Purpose
kubectl config get-contexts
List available clusters
kubectl config use-context <ctx>
Switch cluster
kubectl cluster-info
API server and CoreDNS endpoints
kubectl api-resources
List all resource types
kubectl explain pod.spec
Field documentation
Pods and workloads
Command
Purpose
kubectl get pods -A
All pods in all namespaces
kubectl get pods -o wide
Pods with node and IP
kubectl describe pod <name>
Events, conditions, container state
kubectl logs <pod> -f
Stream container logs
kubectl logs <pod> -c <container>
Logs from one container
kubectl logs <pod> --previous
Logs from crashed container
kubectl exec -it <pod> -- /bin/sh
Shell into running pod
kubectl port-forward pod/<pod> 8080:80
Local access to pod port
kubectl run tmp --image=nginx --rm -it -- /bin/sh
Ephemeral debug pod
kubectl delete pod <name> --grace-period=0 --force
Force delete stuck pod
Deployments, Services, Ingress
Command
Purpose
kubectl get deploy,svc,ing
List common workload objects
kubectl rollout status deploy/<name>
Watch rollout progress
kubectl rollout history deploy/<name>
Revision history
kubectl rollout undo deploy/<name>
Rollback to previous revision
kubectl scale deploy/<name> --replicas=5
Scale replicas
kubectl set image deploy/<name> app=img:v2
Trigger rolling update
kubectl expose deploy <name> --port=80
Create ClusterIP Service
Debugging and troubleshooting
Command
Purpose
kubectl get events --sort-by='.lastTimestamp'
Recent cluster events
kubectl top nodes
Node CPU/memory (needs metrics-server)
kubectl top pods
Pod resource usage
kubectl auth can-i create pods
Check RBAC permission
kubectl get pod <name> -o yaml
Full manifest
kubectl get pods -l app=myapp
Filter by label
kubectl cordon <node>
Mark node unschedulable
kubectl drain <node> --ignore-daemonsets
Evict pods before maintenance
Useful output formats
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
kubectl get nodes -o custom-columns=NAME:.metadata.name,STATUS:.status.conditions[-1].type
kubectl get deploy myapp -o jsonpath='{.spec.replicas}'
Kubernetes YAML Quick Reference
Core API objects every DevOps engineer should recognize.
Deployment + Service + Ingress
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: production
labels:
app: api
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: myregistry/api:1.2.0
ports:
- containerPort: 8080
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
readinessProbe:
httpGet:
path: /ready
port: 8080
envFrom:
- configMapRef:
name: api-config
- secretRef:
name: api-secrets
---
apiVersion: v1
kind: Service
metadata:
name: api
namespace: production
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8080
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: api
namespace: production
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: nginx
tls:
- hosts: [api.example.com]
secretName: api-tls
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api
port:
number: 80
K3s is a lightweight, CNCF-certified Kubernetes distribution from Rancher. Ideal for edge, IoT, CI runners, and homelab clusters. It bundles containerd, CoreDNS, Traefik ingress, local-path storage, and a single binary.
Install
# Server (control plane + worker)
curl -sfL https://get.k3s.io | sh -
# Agent (join worker node)
curl -sfL https://get.k3s.io | K3S_URL=https://<server-ip>:6443 \
K3S_TOKEN=<node-token> sh -
# Node token (on server)
sudo cat /var/lib/rancher/k3s/server/node-token
Compose defines multi-container applications in a single YAML file. Compose Specification v2 is the current standard (use docker compose, not legacy docker-compose).
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- run: npm ci
- run: npm test
- run: npm run build
terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- run: terraform fmt -check
working-directory: infra
- run: terraform init -backend=false
working-directory: infra
- run: terraform validate
working-directory: infra
Pipeline stages (mental model)
Stage
Typical checks
Lint
fmt, eslint, tflint, yamllint
Test
unit tests, terraform validate
Build
docker build, compile artifacts
Scan
trivy, snyk, checkov, tfsec
Deploy
helm upgrade, terraform apply (with approval)
Linux & Shell One-Liners
For deeper Linux coverage, see Linux Fundamentals. These one-liners cover daily DevOps tasks.
Task
Command
Disk usage
df -h && du -sh /* 2>/dev/null | sort -h
Find large files
find / -xdev -type f -size +100M 2>/dev/null
Process on port
ss -tlnp | grep :8080
Follow syslog
journalctl -u nginx -f
HTTP check
curl -sI https://example.com | head -1
DNS lookup
dig +short api.example.com
JSON pretty-print
curl -s url | jq .
Parallel SSH
parallel-ssh -i -H hosts.txt "uptime"
Observability Quick Reference
Signal
Tools
DevOps use
Metrics
Prometheus, Grafana, CloudWatch
SLOs, alerting, capacity
Logs
Loki, ELK, Fluent Bit
Incident triage, audit
Traces
Jaeger, Tempo, OpenTelemetry
Latency debugging
Prometheus PromQL starters
rate(http_requests_total[5m])
histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
up{job="kubernetes-pods"} == 0
Incident checklist
What changed? (deploy, config, traffic, dependency)
Is it global or isolated? (one pod, one AZ, all users)
Check: kubectl get pods, events, recent deploys, dashboards, error rate
Mitigate first (rollback, scale, feature flag), root-cause second
Document timeline and write a blameless postmortem
Keep this page useful: Pin it in your browser, print the sections you use most, and pair it with official docs when you need version-specific behavior. DevOps is a practice of repeatable, observable, automatable systems. These cheat sheets are the shortcuts; understanding the why behind each command is what makes you effective under pressure.