Kawsify

DevOps Cheatsheet

Git CLI

git init

Initialize a new Git repository

git clone repository-url

Clone a repository from a remote source

git status

Show the current status of the working directory and staging area

git add file-name

Stage changes to be committed

git add .

Stage all changes in the working directory

git commit -m 'commit message'

Commit staged changes with a message

git push origin branch-name

Push local commits to a remote branch

git pull origin branch-name

Pull changes from a remote repository to the local branch

git fetch origin

Fetch changes from a remote repository without merging

git merge branch-name

Merge another branch into the current branch

git branch

List all branches in the repository

git branch branch-name

Create a new branch

git checkout branch-name

Switch to a different branch

git checkout -b branch-name

Create a new branch and switch to it

git log

View the commit history

git reset --hard commit-hash

Reset the current branch to a specific commit

git stash

Stash changes that are not yet committed

git stash apply

Reapply stashed changes

git remote add origin repository-url

Add a remote repository

git remote -v

List remote repositories

git tag tag-name

Create a new tag for the current commit

git diff

Show the differences between files in the working directory and the staging area

git rebase branch-name

Reapply commits on top of another branch

git rm file-name

Remove a file from the working directory and staging area

Kubernetes CLI (kubectl & kubeadm)

kubectl get pods

List all pods in the current namespace

kubectl get pods --all-namespaces

List all pods across all namespaces

kubectl describe pod pod-name

Display detailed information about a specific pod

kubectl logs pod-name

Get logs from a specific pod

kubectl exec -it pod-name -- /bin/bash

Run a command inside a running pod (e.g., open a shell)

kubectl get services

List all services in the current namespace

kubectl get deployments

List all deployments in the current namespace

kubectl create deployment deployment-name --image=image-name

Create a new deployment

kubectl delete pod pod-name

Delete a specific pod

kubectl apply -f file.yaml

Apply a configuration from a YAML file

kubectl delete -f file.yaml

Delete resources from a YAML file

kubectl get nodes

List all nodes in the cluster

kubectl cordon node-name

Mark a node as unschedulable

kubectl drain node-name --ignore-daemonsets

Safely evict all pods from a node for maintenance

kubectl uncordon node-name

Mark a node as schedulable again

kubectl scale deployment deployment-name --replicas=5

Scale a deployment to a specific number of replicas

kubectl expose deployment deployment-name --port=80 --target-port=8080

Expose a deployment as a service

kubectl get namespaces

List all namespaces

kubectl config get-contexts

List all available contexts

kubectl config use-context context-name

Switch to a specific context

kubectl rollout status deployment deployment-name

Check the status of a deployment rollout

kubectl port-forward pod-name 8080:80

Forward a local port to a port on a pod

kubectl top nodes

Show CPU and memory usage for nodes

kubectl top pods

Show CPU and memory usage for pods

kubeadm init

Initialize a Kubernetes control-plane node

kubeadm join control-plane-ip:6443 --token token --discovery-token-ca-cert-hash sha256:hash

Join a worker node to the Kubernetes cluster

kubeadm reset

Reset all kubeadm-managed cluster state

kubeadm token create

Create a new token for joining nodes

kubeadm token list

List all tokens for joining nodes

kubeadm config view

View the kubeadm configuration

kubeadm upgrade plan

Check available upgrades for the control-plane node

kubeadm upgrade apply vX.X.X

Upgrade the Kubernetes control-plane node to a specific version

Docker CLI

docker login

Log in to Docker Hub or another registry

docker pull image-name

Pull an image from a Docker registry

docker images

List all downloaded Docker images

docker ps

List all running containers

docker ps -a

List all containers (running and stopped)

docker run -d --name container-name image-name

Run a container in detached mode

docker run -it --name container-name image-name

Run a container in interactive mode with a terminal

docker exec -it container-name bash

Run a bash shell inside a running container

docker stop container-name

Stop a running container

docker start container-name

Start a stopped container

docker rm container-name

Remove a stopped container

docker rmi image-name

Remove an image

docker logs container-name

View logs of a running or stopped container

docker build -t image-name .

Build a Docker image from a Dockerfile

docker-compose up

Start services defined in a docker-compose.yml file

docker-compose down

Stop and remove containers, networks, and volumes created by `docker-compose up`

docker volume ls

List all Docker volumes

docker network ls

List all Docker networks

docker inspect container-name

Get detailed information about a container

docker system prune

Remove all unused containers, networks, images, and volumes

Terraform CLI

terraform --version

Display the Terraform version

terraform init

Initialize a new or existing Terraform working directory

terraform validate

Validate the configuration files

terraform plan

Create an execution plan

terraform apply

Apply the changes required to reach the desired state of the configuration

terraform destroy

Destroy all the resources managed by Terraform

terraform show

Show the current state or plan

terraform fmt

Format Terraform configuration files to a canonical format

terraform state list

List all resources in the state file

terraform state show resource-name

Show details of a resource in the state file

terraform taint resource-name

Mark a resource for recreation during the next apply

terraform untaint resource-name

Mark a resource as not needing recreation

terraform import resource-name id

Import existing infrastructure into Terraform

terraform output

Display the output values from the Terraform state

terraform workspace list

List all Terraform workspaces

terraform workspace new workspace-name

Create a new workspace

terraform workspace select workspace-name

Select an existing workspace

terraform workspace delete workspace-name

Delete a workspace

terraform plan -out=plan.tfplan

Create an execution plan and save it to a file

terraform apply plan.tfplan

Apply a previously created execution plan

terraform validate -json

Validate configuration files and output results in JSON format

terraform graph

Generate a visual representation of the dependency graph

terraform console

Start an interactive console for Terraform expressions

AWS CLI

aws configure

Configure AWS CLI with access key, secret key, region, and output format

aws ec2 describe-instances

List EC2 instances (AWS)

aws s3 cp file s3://bucket-name

Copy files to an S3 bucket (AWS)

aws s3 ls s3://bucket-name

List objects in an S3 bucket (AWS)

aws s3 sync ./local-folder s3://bucket-name

Sync a local folder to an S3 bucket (AWS)

aws eks get-token --cluster-name cluster-name

Get an authentication token for an EKS cluster (AWS)

aws iam list-users

List all IAM users (AWS)

aws ec2 start-instances --instance-ids i-1234567890abcdef0

Start an EC2 instance (AWS)

aws ec2 stop-instances --instance-ids i-1234567890abcdef0

Stop an EC2 instance (AWS)

aws lambda invoke --function-name function-name output.txt

Invoke a Lambda function (AWS)

aws cloudformation describe-stacks

List CloudFormation stacks (AWS)

aws rds describe-db-instances

List RDS database instances (AWS)

aws elb describe-load-balancers

List Elastic Load Balancers (AWS)

aws cloudwatch describe-alarms

List CloudWatch alarms (AWS)

aws ec2 create-key-pair --key-name key-name

Create a new EC2 key pair (AWS)

aws ec2 describe-security-groups

List EC2 security groups (AWS)

aws ec2 allocate-address

Allocate an Elastic IP address (AWS)

aws ec2 describe-volumes

List EC2 volumes (AWS)

aws route53 list-hosted-zones

List Route 53 hosted zones (AWS)

aws ecr get-login-password --region region | docker login --username AWS --password-stdin your_account_id.dkr.ecr.region.amazonaws.com

Log in to AWS Elastic Container Registry (AWS)

DigitalOcean CLI

doctl auth init

Configure DigitalOcean CLI by adding your API token

doctl account get

Retrieve account information (DigitalOcean)

doctl compute droplet list

List all Droplets (DigitalOcean)

doctl compute droplet create droplet-name --region nyc3 --image ubuntu-20-04-x64 --size s-1vcpu-1gb --ssh-keys key-id

Create a new Droplet (DigitalOcean)

doctl compute droplet delete droplet-id

Delete a Droplet (DigitalOcean)

doctl compute ssh droplet-id

SSH into a Droplet (DigitalOcean)

doctl compute snapshot list

List all snapshots (DigitalOcean)

doctl compute snapshot create droplet-id --name snapshot-name

Create a snapshot of a Droplet (DigitalOcean)

doctl compute volume list

List all volumes (DigitalOcean)

doctl compute volume create volume-name --size 10GiB --region nyc1

Create a new block storage volume (DigitalOcean)

doctl kubernetes cluster list

List Kubernetes clusters (DigitalOcean)

doctl kubernetes cluster kubeconfig save cluster-name

Retrieve and save the kubeconfig file for a Kubernetes cluster (DigitalOcean)

doctl databases list

List all managed databases (DigitalOcean)

doctl databases create db-name --engine pg --region nyc3

Create a managed database (PostgreSQL) (DigitalOcean)

doctl projects list

List all projects (DigitalOcean)

doctl projects create --name project-name --purpose web --environment production

Create a new project (DigitalOcean)

doctl compute firewall list

List all firewalls (DigitalOcean)

doctl compute firewall create --name firewall-name --inbound-rules 'protocol:tcp,ports:22,address:0.0.0.0/0'

Create a new firewall (DigitalOcean)

doctl compute load-balancer list

List all load balancers (DigitalOcean)

doctl compute load-balancer create --name lb-name --region nyc3 --droplet-ids droplet-id

Create a new load balancer (DigitalOcean)

Google Cloud CLI (gcloud)

gcloud init

Initialize the Google Cloud CLI and authenticate

gcloud auth login

Login to Google Cloud account

gcloud config set project PROJECT_ID

Set the active project for gcloud (GCP)

gcloud compute instances list

List all Compute Engine instances (GCP)

gcloud compute instances create instance-name --zone=ZONE

Create a new Compute Engine instance (GCP)

gcloud compute instances delete instance-name --zone=ZONE

Delete a Compute Engine instance (GCP)

gcloud compute ssh instance-name --zone=ZONE

SSH into a Compute Engine instance (GCP)

gcloud compute disks list

List all Compute Engine disks (GCP)

gcloud compute disks create disk-name --size=10GB --zone=ZONE

Create a new Compute Engine disk (GCP)

gcloud container clusters list

List all Kubernetes Engine clusters (GCP)

gcloud container clusters create cluster-name --zone=ZONE

Create a new Kubernetes cluster (GCP)

gcloud container clusters get-credentials cluster-name --zone=ZONE

Get credentials for a Kubernetes Engine cluster (GCP)

gcloud functions deploy function-name --runtime=nodejs10 --trigger-http --allow-unauthenticated

Deploy a Google Cloud Function (GCP)

gcloud functions list

List all deployed Cloud Functions (GCP)

gcloud sql instances list

List all Cloud SQL instances (GCP)

gcloud sql instances create instance-name --tier=db-f1-micro --region=REGION

Create a new Cloud SQL instance (GCP)

gcloud storage buckets list

List all Cloud Storage buckets (GCP)

gsutil cp file gs://bucket-name

Copy a file to a Cloud Storage bucket (GCP)

gcloud pubsub topics list

List all Pub/Sub topics (GCP)

gcloud pubsub subscriptions list

List all Pub/Sub subscriptions (GCP)

Azure CLI

az login

Authenticate to your Azure account

az account set --subscription SUBSCRIPTION_ID

Set the active Azure subscription

az vm list

List all virtual machines (Azure)

az vm create --resource-group resource-group-name --name vm-name --image UbuntuLTS

Create a new virtual machine (Azure)

az vm delete --resource-group resource-group-name --name vm-name

Delete a virtual machine (Azure)

az vm start --resource-group resource-group-name --name vm-name

Start a virtual machine (Azure)

az vm stop --resource-group resource-group-name --name vm-name

Stop a virtual machine (Azure)

az network vnet list

List all virtual networks (Azure)

az network vnet create --name vnet-name --resource-group resource-group-name --address-prefix 10.0.0.0/16

Create a new virtual network (Azure)

az storage account list

List all storage accounts (Azure)

az storage blob upload --account-name account-name --container-name container-name --name blob-name --file path/to/file

Upload a blob to Azure Blob storage (Azure)

az storage blob download --account-name account-name --container-name container-name --name blob-name --file path/to/file

Download a blob from Azure Blob storage (Azure)

az aks list

List all Kubernetes clusters (Azure)

az aks create --resource-group resource-group-name --name cluster-name --node-count 1 --enable-addons monitoring --generate-ssh-keys

Create a new Kubernetes cluster (Azure)

az aks get-credentials --resource-group resource-group-name --name cluster-name

Get credentials for a Kubernetes cluster (Azure)

az sql server list

List all SQL servers (Azure)

az sql server create --name server-name --resource-group resource-group-name --location location --admin-user admin-username --admin-password admin-password

Create a new SQL server (Azure)

az functionapp list

List all Function Apps (Azure)

az functionapp create --resource-group resource-group-name --consumption-plan-location location --runtime node --name functionapp-name --storage-account storage-account-name

Create a new Function App (Azure)

az group list

List all resource groups (Azure)

az group create --name resource-group-name --location location

Create a new resource group (Azure)

Linux CLI for DevOps

ls -lah

List directory contents in human-readable format, including hidden files

cd /path/to/directory

Change to a specific directory

mkdir directory-name

Create a new directory

rm -rf directory-name

Recursively delete a directory and its contents

cp source-file destination

Copy files or directories

mv source-file destination

Move or rename files or directories

chmod 755 file-name

Change file permissions

chown user:group file-name

Change file ownership

ps aux

List all running processes

top

Monitor system processes and resource usage in real time

htop

Interactive process viewer (if installed)

df -h

Display disk space usage in human-readable format

du -sh directory-name

Display the size of a directory

free -h

Display available and used memory

grep 'search-string' file-name

Search for a string within a file

find /path -name file-name

Find files or directories by name

tar -czvf archive-name.tar.gz directory-name

Compress a directory into a tar.gz archive

tar -xzvf archive-name.tar.gz

Extract a tar.gz archive

curl -O url

Download a file from the internet using curl

wget url

Download a file from the internet using wget

ssh user@remote-server-ip

Connect to a remote server via SSH

scp file-name user@remote-server:/path

Copy a file to a remote server via SCP

rsync -avz source destination

Sync files between local and remote systems

systemctl status service-name

Check the status of a service

systemctl start service-name

Start a service

systemctl stop service-name

Stop a service

systemctl restart service-name

Restart a service

journalctl -xe

View detailed logs from system services

crontab -e

Edit the cron jobs for the current user

netstat -tuln

Show listening ports and active connections

ss -tuln

Show socket statistics, including listening ports

ping hostname-or-ip

Ping a remote server to check connectivity

traceroute hostname-or-ip

Trace the route packets take to a network host

iptables -L

List firewall rules using iptables

Monitoring & Logging

prometheus --config.file=prometheus.yml

Start Prometheus with a config file

grafana-server --config=/etc/grafana/grafana.ini

Start Grafana server

elasticsearch

Start Elasticsearch

kibana

Start Kibana

logstash -f logstash.conf

Start Logstash with a config file

filebeat -e -c filebeat.yml

Start Filebeat with a config file

curl -X GET "localhost:9200/_cat/health"

Check Elasticsearch cluster health

journalctl -u service-name

View logs for a specific systemd service

Ansible CLI

ansible --version

Display the Ansible version

ansible localhost -m ping

Ping localhost to test connectivity

ansible all -i inventory.ini -m ping

Ping all hosts listed in the inventory file

ansible-playbook playbook.yml

Run a playbook

ansible-playbook playbook.yml --check

Run a playbook in check mode (dry run)

ansible-playbook playbook.yml --diff

Show differences between the current and desired states

ansible-galaxy collection install collection-name

Install an Ansible collection from Galaxy

ansible-galaxy role install role-name

Install an Ansible role from Galaxy

ansible-inventory --list

List all inventory hosts and their variables

ansible-inventory -i inventory.ini --graph

Display the inventory as a graph

ansible-vault encrypt file.yml

Encrypt a file using Ansible Vault

ansible-vault decrypt file.yml

Decrypt an encrypted file using Ansible Vault

ansible-vault rekey file.yml

Change the password for an encrypted file

ansible-vault edit file.yml

Edit an encrypted file using Ansible Vault

ansible-lint playbook.yml

Lint an Ansible playbook for best practices

ansible-doc -l

List all available modules

ansible-doc module-name

Display documentation for a specific module

ansible-playbook playbook.yml --start-at-task='task-name'

Start executing a playbook from a specific task

ansible-playbook playbook.yml --tags 'tag-name'

Run only tasks with a specific tag

ansible-playbook playbook.yml --skip-tags 'tag-name'

Skip tasks with a specific tag

OpenTofu CLI

opentofu --version

Display the OpenTofu version

opentofu init

Initialize a new or existing OpenTofu working directory

opentofu validate

Validate the configuration files

opentofu plan

Create an execution plan

opentofu apply

Apply the changes required to reach the desired state of the configuration

opentofu destroy

Destroy all the resources managed by OpenTofu

opentofu show

Show the current state or plan

opentofu fmt

Format OpenTofu configuration files to a canonical format

opentofu state list

List all resources in the state file

opentofu state show resource-name

Show details of a resource in the state file

opentofu taint resource-name

Mark a resource for recreation during the next apply

opentofu untaint resource-name

Mark a resource as not needing recreation

opentofu import resource-name id

Import existing infrastructure into OpenTofu

opentofu output

Display the output values from the OpenTofu state

opentofu workspace list

List all OpenTofu workspaces

opentofu workspace new workspace-name

Create a new workspace

opentofu workspace select workspace-name

Select an existing workspace

opentofu workspace delete workspace-name

Delete a workspace

opentofu plan -out=plan.tfplan

Create an execution plan and save it to a file

opentofu apply plan.tfplan

Apply a previously created execution plan

opentofu validate -json

Validate configuration files and output results in JSON format

opentofu graph

Generate a visual representation of the dependency graph

opentofu console

Start an interactive console for OpenTofu expressions

Terragrunt CLI

terragrunt --version

Display the Terragrunt version

terragrunt init

Initialize a Terragrunt working directory, including Terraform modules

terragrunt validate

Validate Terragrunt and Terraform configuration files

terragrunt plan

Create an execution plan for Terraform using Terragrunt

terragrunt apply

Apply the changes required to reach the desired state of the configuration

terragrunt destroy

Destroy all resources managed by Terraform using Terragrunt

terragrunt show

Show the current state or plan

terragrunt output

Display the output values from the Terraform state

terragrunt plan-all

Create execution plans for all modules defined in Terragrunt configurations

terragrunt apply-all

Apply the changes required to reach the desired state of all modules

terragrunt destroy-all

Destroy all resources managed by Terraform across all modules

terragrunt refresh

Update the state with the latest information from the provider

terragrunt graph

Generate a visual representation of the dependency graph for Terraform resources

terragrunt validate-all

Validate all Terragrunt and Terraform configurations

terragrunt get

Download and update Terraform modules

terragrunt run-all command

Run a specified Terraform command (e.g., apply, plan) across all modules

terragrunt workspace list

List all Terragrunt workspaces

terragrunt workspace new workspace-name

Create a new workspace

terragrunt workspace select workspace-name

Select an existing workspace

terragrunt workspace delete workspace-name

Delete a workspace