0% found this document useful (0 votes)
87 views12 pages

Devops Tools Cheat Sheet - Merged

Uploaded by

samjain1790
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views12 pages

Devops Tools Cheat Sheet - Merged

Uploaded by

samjain1790
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Git Cheat Sheet

Workflow Local changes (cont.) Collaboration


Command Description Command Description
git diff Show unstaged changes git remote -v List remote repositories
git diff --staged Show staged changes git remote add <name>
Add a new remote repository
<url>
Commit staged changes using the
git commit
default editor Download all changes from a
git fetch <remote> remote repository but don't
Commit staged changes with a integrate them
git commit -m <message> message provided on the
command line Download changes and directly
git pull <remote>
merge/integrate them
git commit --amend Amend the last commit
git pull <remote> Download changes and directly
Start a new repository git reset HEAD <file> Unstage a file <branch> merge/integrate a remote branch
Command Description git checkout -- <file> Discard local changes in a file git push <remote> Upload local changes to a remote
<branch> repository
Create a new repository in the
git init
current directory Branches git push <remote>
Delete a remote branch
--delete <branch>
git clone <url> [<dir>] Clone a remote repository Command Description
git push <remote> --tags Push tags to a remote repository
git branch List local branches
History git branch -r List remote branches
Command Description
Stashing
git branch <branch> Create a new branch
Command Description
git log Show commit logs
git checkout <branch> Switch to a branch
Stash the changes in a dirty
Show commit logs with one line git stash
git log --oneline Create a new branch and switch working directory away
per commit git checkout -b <branch>
to it
git stash list List all stashes
Show the changes of the last
git show Merge a branch into the active
commit git merge <branch> git stash pop Apply the last stash and delete it
branch
Summarize git log output by Apply the last stash but don't
git shortlog git branch -d <branch> Delete a branch git stash apply
author delete it
Show who changed which line in a git stash drop Delete the last stash
git blame <file>
file Tags
git stash clear Delete all stashes
Command Description

Local changes git tag List tags


Writing good commit messages
Command Description git tag <tag> Create a tag
1. Separate subject from body with a blank line
List which files are staged, git tag -a <tag> Create an annotated tag
git status 2. Limit the subject line to 50 characters
unstaged, and untracked
git tag -s <tag> Create a GPG-signed tag 3. Capitalize the subject line
git add <file> Add a file to the staging area 4. Do not end the subject line with a period
git tag -d <tag> Delete a tag
Interactively choose hunks of a 5. Use the imperative mood in the subject line
git add -p git show <tag> Show the tag data 6. Wrap the body at 72 characters
file to add to the staging area
7. Use the body to explain what and why vs. how

© Nic Wortel, Software Consultant & Trainer - Last update: August 3, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
AWS Cheat Sheet
Installation Identity and Access Management (IAM)
Command Description
See https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
aws iam list-users List users
For autocompletion see https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html.
aws iam list-groups List groups
aws iam list-roles List roles
Global flags
aws iam list-policies List policies
Flag Description
aws iam create-user --user-name <name> Create a user
--profile <name> Run a command using the specified profile
aws iam create-group --group-name
--output <style> Format output as (json/text/table/yaml) Create a group
<name>
--help Show help
aws iam create-role --role-name <name>
Create a role
--endpoint-url <url> Override default API endpoint --assume-role-policy-document <policy>

--region Override default region aws iam create-policy --policy-name


Create a policy
<name> --policy-document <policy>
--version Show version of AWS CLI

Elastic Compute Cloud (EC2)


Configuration
Command Description
Command Description
aws ec2 describe-instances List instances
aws configure Configure AWS
aws ec2 run-instances --image-id <id>
aws configure sso Configure AWS IAM Identity Center credentials Create an instance
--instance-type <type>
aws configure list Show current configuration data aws ec2 terminate-instances
Terminate an instance
--instance-ids <id>
aws configure set <key> <value> Set a configuration value
aws ec2 start-instances --instance-ids
aws configure get <key> Show a configuration value Start an instance
<id>
aws ec2 stop-instances --instance-ids
Profiles <id>
Stop an instance

Command Description
aws configure --profile <name> Create a new profile Elastic Kubernetes Service (EKS)
aws configure list-profiles Show available profiles Command Description
aws eks list-clusters List clusters
Account information aws eks describe-cluster --name <name> Describe a cluster
Command Description aws eks create-cluster --name <name> Create a cluster
aws sts get-caller-identity Retrieve account information aws eks delete-cluster --name <name> Delete a cluster

© Nic Wortel, Software Consultant & Trainer - Last update: February 17, 2024 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Relational Database Service (RDS)
Command Description
aws rds describe-db-clusters List clusters
aws rds describe-db-instances List instances
aws rds create-db-cluster-snapshot Create a snapshot of a cluster

Simple Storage Service (S3)


Command Description
aws s3 ls List buckets
aws s3 ls s3://<bucket> List objects in a bucket
aws s3 mb s3://<bucket> Create a bucket
aws s3 rb s3://<bucket> Delete a bucket
aws s3 cp <src> <dest> Copy a file from/to S3
aws s3 rm s3://<bucket>/<object> Delete an object
aws s3 sync s3://bucket <dir> Sync a bucket to a local directory
aws s3 sync <dir> s3://bucket Sync a local directory to an S3 bucket

Other commands
Command Description
aws --version Show version
aws help Show help including all available commands
aws <command> help Show help for a specific command

© Nic Wortel, Software Consultant & Trainer - Last update: February 17, 2024 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Linux Cheat Sheet
File Commands Directory Aliases File Permission Commands
Command Description Alias Directory Command Description
cat <file> Print file contents . Current directory chmod <mode> <file> Change file permissions
touch <file> Create file (or update timestamp) .. Parent directory Add execute permission for the
chmod u+x <file>
owner
cp <src> <dst> Copy a file ~ Home directory
Set file permissions to 644
mv <src> <dst> Move / rename a file chmod 644 <file> (read/write for owner, read for
rm <file> Remove file Link Commands group and everyone else)

head <file> Print first 10 lines of file Command Description Add write permission for the
chmod -R g+w <dir>
group recursively to a directory
tail <file> Print last 10 lines of file ln -s <target> <link> Create symbolic link
chown <owner> <file> Change file owner
Print last 10 lines and any new ln <target> <link> Create hard link
tail -f <file> Change directory owner
lines added to file readlink -f <file> Print absolute path of file chown -R <owner> <dir>
recursively
chown <owner>:<group>
Directory Commands Search Commands <file>
Change file owner and group

Command Description Command Description chgrp <group> <file> Change file group
ls List files in the current directory grep <pattern> <file...> Search for pattern in file(s)
ls <dir> List files in <dir> Search for pattern recursively in a File Permission Bits
grep -r <pattern> <dir>
ls -l List files with details directory Bit Description
ls -a List all files (including hidden) Search for pattern case- 4 Read (r)
grep -i <pattern> <file>
insensitively
ls -al List all files with details 2 Write (w)
Search for lines not matching
grep -v <pattern> <file>
Print the current/working pattern 1 Execute (x)
pwd
directory
grep -n <pattern> <file> Search and print line numbers
Change current directory to First digit represents the owner, the second digit represents the
cd <dir> Find files in <dir> with name group, and the third digit represents everyone else.
<dir> find <dir> -name <name>*
starting with <name>
cd .. Go up one directory For example, 640 means read/write for owner, read for group, and no
Find files in <dir> of type
find <dir> -type <type> permissions for everyone else.
mkdir <dir> Create directory <type>
Create directory and any missing
mkdir -p <dir>
parent directories File Permission User Types
Superuser Commands
cp -r <src> <dst> Copy a directory and its contents User Type Description
Command Description
mv <src> <dst> Move / rename a directory u Owner
sudo <cmd> Run command as superuser (root)
rmdir <dir> Remove an empty directory g Group
su Switch to superuser (root)
Remove a directory and its o Everyone else
rm -r <dir> su <user> Switch to user <user>
contents a All

© Nic Wortel, Software Consultant & Trainer - Last update: October 16, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
System Information Commands Secure Shell (SSH) Commands IO Redirection
Command Description Command Description Command Description
df Show file system disk usage ssh-keygen Generate SSH key pair Replace contents of file with
<cmd> > <file>
output
df -h Show disk usage in MB/GB/TB ssh-add <key> Add SSH key to SSH agent
<cmd> >> <file> Append output to file
du Show disk usage per directory ssh-add -l List SSH keys in SSH agent
<cmd> < <file> Redirect input from file
du -h Show disk usage in MB/GB/TB Copy SSH key to <host> for
ssh-copy-id <user>@<host>
<user> <cmd> 2> <file> Redirect stderr to file
free Show memory usage
Connect to <host> as current <cmd> &> <file> Redirect stdout and stderr to file
free -h Show memory usage in MB/GB/TB ssh <host>
user
uptime Show uptime ssh <user>@<host> Connect to <host> as <user>
Pipe Commands
whoami Show current user Copy local file <src> to <dest>
scp <src> <host>:<dest> Command Description
uname Show system information on <host>
<cmd1> | <cmd2> Pipe stdout to next cmd
uname -a Show all system information Copy file <src> from <host> to
scp <host>:<src> <dest>
local <dest> <cmd1> |& <cmd2> Pipe stderr to next cmd

Shutdown/Reboot Commands
APT Commands (Debian/Ubuntu) Bash Shortcuts
Command Description
Command Description Shortcut Description
Power off the system after 1
shutdown apt install <pkg> Install package Ctrl + C Stop current command
minute
shutdown now Power off the system immediately apt remove <pkg> Remove package Ctrl + A Go to beginning of line

shutdown 16:30 Power off the system at 16:30 apt purge <pkg> Remove package and config files Ctrl + E Go to end of line

shutdown -c Cancel a scheduled shutdown apt update Update package list Ctrl + K Cut current line

reboot Reboot system apt upgrade Upgrade packages Ctrl + L Clear screen

poweroff Power off system apt search <term> Search for package


Directory Structure
Process Commands Other Commands Directory Description

Command Description Command Description / Root

ps List processes echo <msg> Print message to stdout /bin Binary or executable programs

ps -ef List all processes man <cmd> Display manual page for <cmd> /etc System configuration files

top Display processes in real time Display history of given /home User home directories
history
commands
kill <pid> Kill process /opt Optional or third-party software
which <cmd> Find path to executable <cmd>
pkill <name> Kill process with name /tmp Temporary files
Locate binary, source, and
whereis <cmd> /usr User programs
killall <name> Kill all processes with name manual page for <cmd>
/var Variable data
/var/log Log files

© Nic Wortel, Software Consultant & Trainer - Last update: October 16, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Terraform Cheat Sheet

Installation Managing state


Command Description
See https://developer.hashicorp.com/terraform/downloads for installation instructions for your platform.
Then run terraform -install-autocomplete to enable shell autocompletion. terraform show Show the current state in human-readable form
terraform show <file> Show a human-readable state or plan file
Initializing Terraform terraform show -json <file> Show a state or plan file in JSON format
Command Description
terraform state list List all resources in the state file
terraform init Prepare your working directory for other commands
terraform state show <resource> Show details about a resource
Upgrade modules/providers to the latest allowed
terraform init -upgrade terraform state mv <source> <dest> Rename a resource in the state file
versions
terraform state rm <resource> Remove a resource from the state file
terraform get Only download and install modules
terraform state replace-provider <from>
Replace provider for resources in the state
<to>
Making infrastructure changes
terraform import <resource> <remote_id> Import existing infrastructure into Terraform
Command Description
terraform state pull Pull current state and output to stdout
terraform plan Show changes required by the current configuration
terraform refresh (Deprecated) Update state to match reality
terraform plan -out=<file> Write the plan to a file to apply it later
terraform plan -target <resource> Create a plan for a specific module or resource
Tainting resources
terraform plan -replace <resource> Force the plan to replace a specific resource
Command Description
terraform plan -var '<key>=<value>' Set a value for one of the input variables
terraform taint <resource> (Deprecated) Mark a resource to be replaced
terraform plan -refresh-only Inspect resource drift without updating the state file
terraform untaint <resource> Mark a resource as no longer tainted
terraform apply Create or update infrastructure
terraform apply <file> Create or update infrastructure using a plan file Destroying infrastructure
terraform apply -target <resource> Create or update a specific resource Command Description
terraform apply -replace <resource> Force the replacement of a specific resource terraform destroy Destroy infrastructure managed by Terraform
terraform apply -auto-approve Skip interactive approval of plan before applying terraform destroy -target <resource> Destroy a specific resource

Inspecting output values Formatting and validation


Command Description Command Description
terraform output Show all output values terraform validate Check whether the configuration is valid
terraform output -json Show all output values in JSON format terraform fmt Reformat your configuration in the standard style
terraform output <name> Show a specific output value
Check whether the configuration is formatted
terraform fmt -check
terraform output -raw <name> Show a specific output value without quotes correctly, return non-zero exit code if not

© Nic Wortel, Software Consultant & Trainer - Last update: August 18, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Terraform Cloud / Remote Authentication Conditional Expressions
Command Description Syntax Description
terraform login Log in to Terraform Cloud If condition is true, return true, otherwise return
condition ? true : false
false
terraform login <hostname> Log in to a different host
terraform logout Log out of Terraform Cloud
Splat Expressions
terraform logout <hostname> Log out of a different host
Syntax Description
Return a list of values for the given attribute of all
Managing workspaces <RESOURCE_TYPE>.<NAME>[*].<ATTRIBUTE>
instances of a resource
Command Description
terraform workspace list List all existing workspaces Resource Meta-Arguments
terraform workspace show Show the name of the current workspace Argument Description
terraform workspace select <name> Select a different workspace depends_on Explicitly specify resource dependencies
terraform workspace new <name> Create a new workspace count Create multiple instances of a resource
terraform workspace delete <name> Delete an existing workspace Create an instance of a resource for each element in
for_each
a map or set

Other commands Specify a provider configuration block to use for this


provider
resource
Command Description
Configure the behavior of a resource over its
lifecycle
terraform providers Show the providers required for this configuration lifetime
terraform force-unlock <lock-id> Release a stuck lock
terraform console Try Terraform expressions at an interactive prompt Lifecycle Meta-Argument Attributes
terraform graph | dot -Tpng > graph.png Generate a visual graph of Terraform resources Argument Description

terraform version Show the current Terraform version Create the new resource before destroying the old
create_before_destroy
one
terraform -help Show help output for Terraform
prevent_destroy Prevent Terraform from destroying the resource
terraform -help <command> Show help output for a specific Terraform command
ignore_changes Ignore changes to specific resource attributes

Referencing Named Values


Syntax Description
<RESOURCE_TYPE>.<NAME> Reference to a managed resource
var.<NAME> Reference to an input variable
local.<NAME> Reference to a local value
module.<MODULE NAME> Reference to a child module
data.<DATA TYPE>.<NAME> Reference to a data source

© Nic Wortel, Software Consultant & Trainer - Last update: August 18, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Docker Cheat Sheet

Installation Container registry commands


Command Description
Install Docker Engine (https://docs.docker.com/engine/install/, Linux only) or Docker Desktop
(https://docs.docker.com/desktop/, Linux, macOS and Windows). docker login Login to Docker Hub
docker login <server> Login to another container registry
Container commands docker logout Logout of Docker Hub
Command Description
docker logout <server> Logout of another container registry
docker run <image> Create and run a new container
docker push <image> Upload an image to a registry
docker run -p 8080:80 <image> Publish container port 80 to host port 8080
docker pull <image> Download an image from a registry
docker run -d <image> Run a container in the background
docker search <image> Search Docker Hub for images
docker run -v <host>:<container>
Mount a host directory to a container
<image>
System commands
docker ps List currently running containers
Command Description
docker ps --all List all containers (running or stopped)
docker system df Show Docker disk usage
docker logs <container_name> Fetch the logs of a container
docker system prune Remove unused data
docker logs -f <container_name> Fetch and follow the logs of a container
docker system prune -a Remove all unused data
docker stop <container_name> Stop a running container
docker start <container_name> Start a stopped container
Docker Compose
docker rm <container_name> Remove a container
Command Description
docker compose up Create and start containers
Executing commands in a container
docker compose up -d Create and start containers in background
Command Description
docker compose up --build Rebuild images before starting containers
docker exec <container_name> <command> Execute a command in a running container
docker compose stop Stop services
docker exec -it <container_name> bash Open a shell in a running container
docker compose down Stop and remove containers and networks
docker compose ps List running containers
Image commands
docker compose logs View the logs of all containers
Command Description
docker compose logs <service> View the logs of a specific service
Build a new image from the Dockerfile in the current
docker build -t <image> .
directory and tag it docker compose logs -f View and follow the logs
docker images List local images docker compose pull Pull the latest images
docker rmi <image> Remove an image docker compose build Build or rebuild services

© Nic Wortel, Software Consultant & Trainer - Last update: August 3, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
See https://docs.docker.com/engine/reference/builder/ for the full Dockerfile reference.
Dockerfile instructions
Instruction Description
Dockerfile best practices
FROM <image> Set the base image
Use the official base images from https://hub.docker.com/
FROM <image> AS <name> Set the base image and name the build stage
Use the COPY instruction instead of ADD unless you need to extract a tar file
RUN <command> Execute a command Use the COPY --chown instruction to set the owner of copied files
RUN ["exec", "param1", "param2"] Execute a command
CMD ["exec", "param1", "param2"] Execute a command when the container starts
ENTRYPOINT ["exec", "param1"] Configure the container to run as an executable
ENV <key>=<value> Set an environment variable
EXPOSE <port> Expose a port
COPY <src> <dest> Copy files from source to destination
COPY --from=<name> <src> <dest> Copy files from a build stage to destination
WORKDIR <path> Set the working directory
VOLUME <path> Create a mount point
USER <user> Set the user
ARG <name> Define a build argument
ARG <name>=<default> Define a build argument with a default value
LABEL <key>=<value> Set a metadata label
HEALTHCHECK <command> Set a healthcheck command

© Nic Wortel, Software Consultant & Trainer - Last update: August 3, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Helm Cheat Sheet

Helm Listing releases


Command Description
Helm is the package manager for Kubernetes. See https://helm.sh/docs/intro/install/ for installation
instructions. helm list List all releases in the current namespace
helm list --all-namespaces List all releases in all namespaces
Global flags helm list -l <label>=<value> List releases with a specific label
Flag Description
helm list --date List releases sorted by date
--kube-context <name> Name of the Kubernetes context to use
helm list List releases that are in a pending/failed/uninstalled
--namespace <name> Namespace to use for this operation --(pending|failed|uninstalled) state
helm status <name> Show the status of a release
Repository management
Command Description Managing releases
helm repo add <name> <url> Add a repository Command Description

helm repo list List all added repositories helm upgrade <name> <chart> Upgrade a release

helm repo update Update the local cache of available charts helm upgrade <name> <chart> --atomic Upgrade a release atomically

helm repo remove <name> Remove a repository helm upgrade <name> <chart>
Upgrade a release and update dependencies
--dependency-update
helm search repo List all charts in the repositories
helm upgrade <name> <chart> --version
helm search repo <keyword> Search for a chart in the repositories Upgrade a release to a specific version
<version>
helm upgrade <name> <chart> --set
Upgrade a release with specific values
Installing Helm charts <key>=<value>

Command Description helm rollback <release> <revision> Rollback a release to a previous revision
helm install <name> <chart> Install a chart with a name
helm install <chart> --generate-name Install a chart, auto-generating a name Developing charts
helm install <name> <chart> --namespace Command Description
Install a chart in a specific namespace
<namespace>
helm create <name> Create a new chart
helm install <name> <chart> --set
Install a chart with specific values
<key>=<value> helm package <chart-path> Package a chart directory into a chart file
helm install <name> <chart> --values <file> Install a chart using a values file
helm lint <chart> Lint a chart
helm install <name> <chart> --dry-run --debug Run a test installation to validate the chart
helm show all <chart> Inspect a chart and list all resources
helm install <name> <chart> --verify Verify the package before installing
helm show values <chart> Inspect a chart and show default values
helm install <name> <chart>
Update dependencies before installing
--dependency-update helm template <name> <chart> Render templates locally
helm uninstall <name> Uninstall a release
helm template <name> <chart> --set
Render templates locally and override values
helm uninstall <name> --keep-history Uninstall a release, keeping the history <key>=<value>

© Nic Wortel, Software Consultant & Trainer - Last update: December 20, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Kubernetes Cheat Sheet

Installation Apply configuration manifests


Command Description
Install the kubectl command line tool to interact with the Kubernetes API:
https://kubernetes.io/docs/tasks/tools/#kubectl kubectl apply -f <file> Apply a manifest from a file
kubectl apply -f <dir> Apply all manifests in a directory
Enable autocompletion in bash:
kubectl apply -k <dir> Apply resources from a kustomize directory
composer completion bash | sudo tee /etc/bash_completion.d/kubectl

Create resources manually


Global flags
Command Description
Flag Description
kubectl run <name> --image=<image> Start a pod
--namespace <namespace> The name of the namespace to use
kubectl create deployment <name>
--context <context> The name of the context to use Create a deployment
--image=<image>
--help Show information about a given command kubectl expose pod <pod> --port=<port> Create a service for an existing pod
kubectl expose deployment <name>
Create a service for an existing deployment
Context and configuration --port=<port>
Command Description kubectl create ingress <name>
Create an ingress that routes traffic to a service
--rule=<host/path=svc:port>
kubectl config get-contexts List all contexts
kubectl create job <name>
kubectl config current-context Display the current context Create a job
--image=<image>
kubectl config use-context <context> Switch to another context kubectl create job <name>
Create a job from a cronjob
kubectl config delete-context <context> Delete the specified context from the kubeconfig --from=cronjob/<name>
kubectl create cronjob <name>
Create a cronjob, using a schedule in Cron format
--image=<image> --schedule=<schedule>
Display resources
kubectl create secret generic <name>
Command Description Create a secret containing <key> and <value>
--from-literal=<key>=<value>
List all resources of this type in the current kubectl create secret docker-registry
kubectl get <resource>
namespace <name> --docker-server=<server>
Create a secret for a Docker registry
kubectl get <resource> -o wide List all resources with more details --docker-username=<username>
--docker-password=<password>
kubectl get <resource> -A List all resources of this type in all namespaces
kubectl get <resource> <name> List a particular resource
Generate YAML configuration manifests
kubectl get <resource> <name> -o yaml Print a particular resource in YAML format
Command Description
kubectl get <resource> <name> -l List resources where label <key1> contains
kubectl create deployment <name>
<key1>=<value1> <value1>
--image=<image> --dry-run=client -o Generate a deployment manifest
kubectl describe <resource> Show detailed information about a resource yaml
kubectl expose deployment <name>
Generate a service manifest for a deployment
--port=<port> --dry-run=client -o yaml

© Nic Wortel, Software Consultant & Trainer - Last update: December 20, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
Edit resources Execute commands
Command Description Command Description
kubectl edit <resource> <name> Edit a resource in a text editor kubectl exec <pod> -- <command> Execute a command in a running pod
kubectl set image <resource> <name> kubectl exec -it <pod> -- sh Open a shell in a running pod
Update the image of a container in a pod
<container>=<image>

View logs
Set labels and annotations Command Description
Command Description
kubectl logs <pod> Print the logs for a pod
kubectl label <resource> <name>
Add a label to a resource kubectl logs -f <pod> Print the logs for a pod and keep streaming
<key>=<value>
kubectl annotate <resource> <name>
Add an annotation to a resource
<key>=<value> Resource usage
Command Description
Delete resources kubectl top node Show resource (CPU/memory) usage of nodes
Command Description kubectl top pod Show resource (CPU/memory) usage of pods
kubectl delete <resource> <name> Delete a particular resource

kubectl delete <resource> --all


Delete all resources of a particular type in the Other commands
current namespace
Command Description
kubectl delete -f <file> Delete a resource from a file
kubectl version Show the version of the client and server
kubectl api-resources Print the supported API resources on the server
Manage deployments
Command Description
kubectl rollout status deployment
Show the status of a deployment rollout
<name>
kubectl rollout history deployment
View the rollout history of a deployment
<name>
kubectl rollout undo deployment <name> Undo a previous rollout deployment
kubectl rollout restart deployment
Restart a deployment
<name>
kubectl scale deployment <name>
Scale a deployment to <n> replicas
--replicas=<n>
kubectl autoscale deployment <name> Autoscale a deployment between <n> and <n>
--min=<min> --max=<max> replicas

© Nic Wortel, Software Consultant & Trainer - Last update: December 20, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets

You might also like