From b7e545884d43b0db36f5a0b345c4f81b244552a6 Mon Sep 17 00:00:00 2001 From: Trever Ehrfurth Date: Mon, 24 Jun 2024 12:54:27 -0500 Subject: [PATCH] Add Cheat Sheet Posts --- _posts/2024-06-24-Docker-Commands.md | 103 ++++++++++++++++++++++++ _posts/2024-06-24-Helm-Commands.md | 54 +++++++++++++ _posts/2024-06-24-Kubectl-Commands.md | 92 +++++++++++++++++++++ _posts/2024-06-24-Terraform-Commands.md | 74 +++++++++++++++++ 4 files changed, 323 insertions(+) create mode 100644 _posts/2024-06-24-Docker-Commands.md create mode 100644 _posts/2024-06-24-Helm-Commands.md create mode 100644 _posts/2024-06-24-Kubectl-Commands.md create mode 100644 _posts/2024-06-24-Terraform-Commands.md diff --git a/_posts/2024-06-24-Docker-Commands.md b/_posts/2024-06-24-Docker-Commands.md new file mode 100644 index 0000000..f8f1399 --- /dev/null +++ b/_posts/2024-06-24-Docker-Commands.md @@ -0,0 +1,103 @@ +--- +title: Docker Commands - Cheat Sheet +description: Helpful Docker commands to reference as a cheat sheet +date: 2024-06-24 12:50:00 -0500 +categories: [Cheat Sheets, Docker] +tags: [docker, cheat sheet, commands] # TAG names should always be lowercase +--- + +# Docker + +## Running Containers + +| COMMAND | DESCRIPTION | +| --- | --- | +| `docker run ` | Start a new container from an image | +| `docker run -it ` | Start a new container in interactive mode | +| `docker run --rm ` | Start a new container and remove it when it exits | +| `docker create ` | Create a new container | +| `docker start ` | Start a container | +| `docker stop ` | Graceful stop a container | +| `docker kill ` | Kill (SIGKILL) a container | +| `docker restart ` | Graceful stop and restart a container | +| `docker pause ` | Suspend a container | +| `docker unpause ` | Resume a container | +| `docker rm ` | Destroy a container | + +## Container Bulk Management + +| COMMAND | DESCRIPTION | +| --- | --- | +| `docker stop $(docker ps -q)` | To stop all the running containers | +| `docker stop $(docker ps -a -q)` | To stop all the stopped and running containers | +| `docker kill $(docker ps -q)` | To kill all the running containers | +| `docker kill $(docker ps -a -q)` | To kill all the stopped and running containers | +| `docker restart $(docker ps -q)` | To restart all running containers | +| `docker restart $(docker ps -a -q)` | To restart all the stopped and running containers | +| `docker rm $(docker ps -q)` | To destroy all running containers | +| `docker rm $(docker ps -a -q)` | To destroy all the stopped and running containers | +| `docker pause $(docker ps -q)` | To pause all running containers | +| `docker pause $(docker ps -a -q)` | To pause all the stopped and running containers | +| `docker start $(docker ps -q)` | To start all running containers | +| `docker start $(docker ps -a -q)` | To start all the stopped and running containers | +| `docker rm -vf $(docker ps -a -q)` | To delete all containers including its volumes use | +| `docker rmi -f $(docker images -a -q)` | To delete all the images | +| `docker system prune` | To delete all dangling and unused images, containers, cache and volumes | +| `docker system prune -a` | To delete all used and unused images | +| `docker system prune --volumes` | To delete all docker volumes | + +## Inspect Containers + +| COMMAND | DESCRIPTION | +| --- | --- | +| `docker ps` | List running containers | +| `docker ps --all` | List all containers, including stopped | +| `docker logs ` | Show a container output | +| `docker logs -f ` | Follow a container output | +| `docker top ` | List the processes running in a container | +| `docker diff` | Show the differences with the image (modified files) | +| `docker inspect` | Show information of a container (json formatted) | + +## Executing Commands + +| COMMAND | DESCRIPTION | +| --- | --- | +| `docker attach ` | Attach to a container | +| `docker cp : ` | Copy files from the container | +| `docker cp :` | Copy files into the container | +| `docker export ` | Export the content of the container (tar archive) | +| `docker exec ` | Run a command inside a container | +| `docker exec -it /bin/bash` | Open an interactive shell inside a container (there is no bash in some images, use /bin/sh) | +| `docker wait ` | Wait until the container terminates and return the exit code | + +## Images + +| COMMAND | DESCRIPTION | +| --- | --- | +| `docker image ls` | List all local images | +| `docker history ` | Show the image history | +| `docker inspect ` | Show information (json formatted) | +| `docker tag ` | Tag an image | +| `docker commit ` | Create an image (from a container) | +| `docker import ` | Create an image (from a tarball) | +| `docker rmi ` | Delete images | +| `docker pull /:` | Pull an image from a registry | +| `docker push /:` | Push and image to a registry | +| `docker search ` | Search an image on the official registry | +| `docker login` | Login to a registry | +| `docker logout` | Logout from a registry | +| `docker save /:` | Export an image/repo as a tarball | +| `docker load` | Load images from a tarball | + +## Volumes + +| COMMAND | DESCRIPTION | +| --- | --- | +| `docker volume ls` | List all vol1umes | +| `docker volume create ` | Create a volume | +| `docker volume inspect ` | Show information (json formatted) | +| `docker volume rm ` | Destroy a volume | +| `docker volume ls --filter="dangling=true"` | List all dangling volumes (not referenced by any container) | +| `docker volume prune` | Delete all volumes (not referenced by any container) | +| `docker run --rm --volumes-from -v $(pwd):/backup busybox tar cvfz /backup/backup.tar ` | Backup a container | +| `docker run --rm --volumes-from -v $(pwd):/backup busybox sh -c "cd && tar xvf /backup/backup.tar --strip 1"` | Restore a container from backup | \ No newline at end of file diff --git a/_posts/2024-06-24-Helm-Commands.md b/_posts/2024-06-24-Helm-Commands.md new file mode 100644 index 0000000..6cd2fc8 --- /dev/null +++ b/_posts/2024-06-24-Helm-Commands.md @@ -0,0 +1,54 @@ +--- +title: Helm Commands - Cheat Sheet +description: Helpful Helm commands to reference as a cheat sheet +date: 2024-06-24 12:51:00 -0500 +categories: [Cheat Sheets, Helm] +tags: [helm, cheat sheet, commands] # TAG names should always be lowercase +--- + +# Helm + +## Repository Management + +| Command | Description | +| --- | --- | +| `helm repo list` | List Helm repositories | +| `helm repo update` | Update list of Helm charts from repositories | + +## Chart Management + +| Command | Description | +| --- | --- | +| `helm search` | List all installed charts | +| `helm search ` | Search for a chart | +| `helm ls` | List all installed Helm charts | +| `helm ls --deleted` | List all deleted Helm charts | +| `helm ls --all` | List installed and deleted Helm charts | +| `helm inspect values /` | Inspect the variables in a chart | + +## Install/Delete Helm Charts + +| Command | Description | +| --- | --- | +| `helm install --name /` | Install a Helm chart | +| `helm install --name --values /` | Install a Helm chart and override variables | +| `helm status ` | Show status of Helm chart being installed | +| `helm delete --purge ` | Delete a Helm chart | + +## Upgrading Helm Charts + +| Command | Description | +| --- | --- | +| `helm get values ` | Return the variables for a release | +| `helm upgrade --values /` | Upgrade the chart or variables in a release | +| `helm history ` | List release numbers | +| `helm rollback 1` | Rollback to a previous release number | + +## Creating Helm Charts + +| Command | Description | +| --- | --- | +| `helm create ` | Create a blank chart | +| `helm lint ` | Lint the chart | +| `helm package ` | Package the chart into foo.tgz | +| `helm dependency update` | Install chart dependencies | \ No newline at end of file diff --git a/_posts/2024-06-24-Kubectl-Commands.md b/_posts/2024-06-24-Kubectl-Commands.md new file mode 100644 index 0000000..a75d338 --- /dev/null +++ b/_posts/2024-06-24-Kubectl-Commands.md @@ -0,0 +1,92 @@ +--- +title: Kubectl Commands - Cheat Sheet +description: Helpful Kubectl commands to reference as a cheat sheet +date: 2024-06-24 12:51:00 -0500 +categories: [Cheat Sheets, Kubectl] +tags: [kubectl, cheat sheet, commands] # TAG names should always be lowercase +--- + +# Kubectl Cheat-Sheet + +## Contexts and Configuration + +| Command | Description | +| --- | --- | +| `kubectl config view` | Show the current kubeconfig file | +| `kubectl config get-contexts` | List all contexts in the kubeconfig file | +| `kubectl config current-context` | Show the current context | +| `kubectl config use-context ` | Change the current context | +| `kubectl config set-context --namespace=` | Set the namespace for a context | +| `kubectl config set-context --cluster=` | Set the cluster for a context | +| `kubectl config set-context --user=` | Set the user for a context | +| `kubectl config set-context --namespace= --cluster= --user=` | Set all context properties | + +## Cluster Management + +| Command | Description | +| --- | --- | +| `kubectl cluster-info` | Display addresses of the master and services | +| `kubectl get nodes` | List all nodes in the cluster | +| `kubectl get pods` | List all pods in the cluster | +| `kubectl get services` | List all services in the cluster | +| `kubectl get deployments` | List all deployments in the cluster | +| `kubectl get namespaces` | List all namespaces in the cluster | +| `kubectl get events` | List all events in the cluster | + +## Resource Management + +| Command | Description | +| --- | --- | +| `kubectl apply -f ` | Apply a configuration file | +| `kubectl delete -f ` | Delete a configuration file | +| `kubectl get ` | List all resources of a type | +| `kubectl describe ` | Describe a resource | +| `kubectl edit ` | Edit a resource | +| `kubectl exec -it -- ` | Execute a command in a pod | + +## Pod Management + +| Command | Description | +| --- | --- | +| `kubectl run --image=` | Create a new pod | +| `kubectl delete pod ` | Delete a pod | +| `kubectl get pod ` | Get details of a pod | +| `kubectl describe pod ` | Describe a pod | +| `kubectl logs ` | Show logs of a pod | +| `kubectl exec -it -- /bin/bash` | Execute a command in a pod | +| `kubectl cp : ` | Copy files from a pod | +| `kubectl top node` | Show metrics for all nodes | +| `kubectl top pod` | Show metrics for all pods | +| `kubectl top pod ` | Show metrics for a specific pod | + +## Service Management + +| Command | Description | +| --- | --- | +| `kubectl expose pod --port=444 --target-port=555` | Expose a pod as a service | +| `kubectl delete service ` | Delete a service | +| `kubectl get service ` | Get details of a service | +| `kubectl describe service ` | Describe a service | + +## Deployment Management + +| Command | Description | +| --- | --- | +| `kubectl create deployment --image=` | Create a new deployment | +| `kubectl delete deployment ` | Delete a deployment | +| `kubectl get deployment ` | Get details of a deployment | +| `kubectl describe deployment ` | Describe a deployment | +| `kubectl scale deployment --replicas=3` | Scale a deployment to 3 replicas | +| `kubectl rollout status deployment/` | Check the status of a deployment rollout | +| `kubectl rollout history deployment/` | Show the history of a deployment rollout | +| `kubectl rollout undo deployment/` | Rollback a deployment to the previous version | +| `kubectl rollout undo deployment/ --to-revision=1` | Rollback a deployment to a specific revision | + +## Namespace Management + +| Command | Description | +| --- | --- | +| `kubectl create namespace ` | Create a new namespace | +| `kubectl delete namespace ` | Delete a namespace | +| `kubectl get namespace ` | Get details of a namespace | +| `kubectl describe namespace ` | Describe a namespace | \ No newline at end of file diff --git a/_posts/2024-06-24-Terraform-Commands.md b/_posts/2024-06-24-Terraform-Commands.md new file mode 100644 index 0000000..c7937ca --- /dev/null +++ b/_posts/2024-06-24-Terraform-Commands.md @@ -0,0 +1,74 @@ +--- +title: Terraform Commands - Cheat Sheet +description: Helpful Terraform commands to reference as a cheat sheet +date: 2024-06-24 12:51:00 -0500 +categories: [Cheat Sheets, Terraform] +tags: [terraform, cheat sheet, commands] # TAG names should always be lowercase +--- + +# Terraform Cheat-Sheet + +## Format and Validate + +| Command | Description | +| --- | --- | +| `terraform fmt` | Reformat your configuration in the standard style | +| `terraform validate` | Check whether the configuration is valid | + +## Initialize Working Directory + +| Command | Description | +| --- | --- | +| `terraform init` | Prepare your working directory for other commands | + +## Plan, Deploy and Cleanup + +| Command | Description | +| --- | --- | +| `terraform apply --auto-approve` | Create or update infrastructure without confirmation prompt | +| `terraform destroy --auto-approve` | Destroy previously-created infrastructure without confirmation prompt | +| `terraform plan -out plan.out` | Output the deployment plan to plan.out | +| `terraform apply plan.out` | Use the plan.out to deploy infrastructure | +| `terraform plan -destroy` | Outputs a destroy plan | +| `terraform apply -target=aws_instance.myinstance` | Only apply/deploy changes to targeted resource | +| `terraform apply -var myregion=us-east-1` | Pass a variable via CLI while applying a configuration | +| `terraform apply -lock=true` | Lock the state file so it can't be modified | +| `terraform apply refresh=false` | Do not reconcile state file with real-world resources | +| `terraform apply --parallelism=5` | Number of simultaneous resource operations | +| `terraform refresh` | Reconcile the state in Terraform state file with real-world resources | +| `terraform providers` | Get informatino about providers used in the current configuration | + +## Workspaces + +| Command | Description | +| --- | --- | +| `terraform workspace new ` | Create a new workspace | +| `terraform workspace select default` | Change to a workspace | +| `terraform workspace list` | List all workspaces | + +## State Manipulation + +| Command | Description | +| --- | --- | +| `terraform state show aws_instance.myinstance` | Show details stored in the Terraform state file | +| `terraform state pull > terraform.tfstate` | Output Terraform state to a file | +| `terraform state mv aws_iam_role.my_ssm_role module.mymodule` | Move a resource tracked via state to different module | +| `terraform state replace-provider hashicorp/aws registry.custom.com/aws` | Replace an existing provider with another | +| `terraform state list` | List all resources tracked in the Terraform state file | +| `terraform state rm aws_instance.myinstance` | Unmanage a resource, delete it from the Terraform state file | + +## Import and Outputs + +| Command | Description | +| --- | --- | +| `terraform import . ` | Import a Resource | +| `terraform output` | List all outputs | +| `terraform output ` | List a specific output | +| `terraform output -json` | List all outputs in JSON format | + +## Terraform Cloud + +| Command | Description | +| --- | --- | +| `terraform login` | Login to Terraform Cloud with an API token | +| `terraform logout` | Logout from Terraform Cloud | \ No newline at end of file