DevOps CLI Cheat Sheet & Explorer

Interactive command search and explorer for Kubectl, Docker Engine, and Docker Compose with live variable substitution.

Interactive Command Reference

Kubectl & Docker Command Explorer

Quickly search, inspect, and copy critical commands across Kubernetes, Docker, and Docker Compose. Type your active namespace, pod, or container names in the variable bar to customize commands on the fly.


Interactive DevOps Tool

Kubectl & Docker Cheat Sheet Explorer

Search, filter, and customize commands in real-time with dynamic variable substitution and flag explanations.

Live Variable Substitution
Type below to update commands instantly
Showing 22 of 22 commands
Safe / Read-only Modifies state Destructive / Danger
read-only Pods & Workloads

List Pods with Node & IP Details

#pods #status #ip #node

List all running and pending pods in the specified namespace with IP, assigned node, and readiness status.

$kubectl get pods -n default -o wide
-nTarget namespace
-o wideDisplays Node, IP, and readiness
read-only Pods & Workloads

List Pods Across Entire Cluster

#cluster-wide #overview

Query all pods across all namespaces simultaneously. Crucial for cluster-wide health checks.

$kubectl get pods -A
-A / -all-namespacesScans all namespaces
read-only Pods & Workloads

Find Unhealthy & Crashing Pods

#troubleshooting #crashloop #errors

Filter only pods that are not in the "Running" state (e.g. CrashLoopBackOff, Pending, Error).

$kubectl get pods -A --field-selector=status.phase!=Running
--field-selectorFilter by server-side resource fields
read-only Pods & Workloads

Deep Inspect Pod & Lifecycle Events

#inspect #oomkilled #events

Displays container state, exit codes, volume mounts, resource limits, and event history for diagnosing crashes.

$kubectl describe pod my-app-pod -n default
danger Pods & Workloads

Force Kill Stuck Terminating Pod

#force #cleanup #stuck

Immediately terminate a stuck pod with zero grace period. Use with caution in production.

$kubectl delete pod my-app-pod -n default --grace-period=0 --force
--grace-period=0Zero delay before SIGKILL
--forceBypass API confirmation delay
modifies Pods & Workloads

Zero-Downtime Rolling Restart of Deployment

#deployment #restart #zero-downtime

Trigger a rolling restart of all pods in a Deployment without changing the deployment spec.

$kubectl rollout restart deployment/my-app-deploy -n default
read-only Pods & Workloads

Track Deployment Rollout Progress

#ci-cd #status #automation

Block and watch until the deployment update finishes or fails with a timeout.

$kubectl rollout status deployment/my-app-deploy -n default
modifies Pods & Workloads

Rollback Deployment to Previous Revision

#rollback #recovery #incident

Instantly revert a bad deployment to the previous stable replica set revision.

$kubectl rollout undo deployment/my-app-deploy -n default
modifies Pods & Workloads

Manually Scale Deployment Replicas

#scale #traffic #capacity

Increase or decrease the replica count of an active deployment.

$kubectl scale deployment/my-app-deploy --replicas=5 -n default
--replicasTarget desired replica count
read-only Debugging & Logs

Stream Live Logs (Follow & Tail)

#logs #stream #tail

Continuously stream real-time logs with the latest 100 lines for immediate debugging.

$kubectl logs -f my-app-pod -n default --tail=100
-fStream logs continuously
--tailNumber of recent lines to display
read-only Debugging & Logs

View Logs of Crashed/Terminated Container

#crash #oom #debug

Retrieve the logs from the previous instance of a pod that died or was OOMKilled.

$kubectl logs my-app-pod -n default -c app --previous
-p / --previousInspect logs from previous terminated container
-cSpecify container inside multi-container pod
modifies Debugging & Logs

Interactive Shell Inside Running Pod

#exec #ssh #terminal #debug

Open an interactive sh/bash terminal session inside a container.

$kubectl exec -it my-app-pod -n default -c app -- /bin/sh
-iPass stdin to container
-tAllocate TTY (pseudo-terminal)
read-only Debugging & Logs

Forward Local Port to Pod or Service

#network #localhost #proxy

Access internal cluster applications, Redis, or databases directly from your localhost browser.

$kubectl port-forward pod/my-app-pod 8080:80 -n default
read-only Debugging & Logs

View Pod CPU & Memory Resource Metrics

#metrics #cpu #memory #hpa

Inspect live CPU millicores and memory megabytes usage using Metrics Server.

$kubectl top pods -n default --sort-by=memory
--sort-bySort output by memory or cpu
modifies Debugging & Logs

Attach Ephemeral Debug Container to Distroless Pod

#distroless #netshoot #troubleshoot

Attach a debug container equipped with curl, netstat, and bash to a stripped distroless pod.

$kubectl debug -it my-app-pod -n default --image=nicolaka/netshoot --target=app
read-only Config & Secrets

Decode Secret Value Directly to Plaintext

#secret #base64 #decode

Extract and decode base64 Kubernetes Secret data keys directly on the CLI.

$kubectl get secret my-secret -n default -o jsonpath='{.data}'
-o jsonpathExtract specific JSON attributes
modifies Config & Secrets

Create Generic Secret from Literal Values

#secret #create #credentials

Quickly create a Kubernetes secret without manually encoding in base64.

$kubectl create secret generic app-secrets --from-literal=DB_PASS=secret123 -n default
read-only Config & Secrets

Generate YAML Manifest via Client-Side Dry Run

#yaml #generator #dry-run

Generate starter Kubernetes manifest YAML without applying it to the cluster.

$kubectl create deployment my-app-deploy --image=nginx:alpine --dry-run=client -o yaml > deployment.yaml
--dry-run=clientRun locally without cluster contact
-o yamlOutput clean YAML manifest
read-only Cluster Admin

View Node CPU & RAM Consumption

#nodes #cluster #capacity

Quickly identify overworked or bottlenecked worker nodes in your cluster.

$kubectl top nodes --sort-by=cpu
danger Cluster Admin

Drain Node Safely for Maintenance

#maintenance #upgrade #drain

Evict all running pods from a node so it can be safely upgraded or replaced.

$kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data
--ignore-daemonsetsPreserves cluster-wide system daemon pods
--delete-emptydir-dataContinues even if pods have temporary emptyDir storage
modifies Cluster Admin

Cordon Node (Mark Unschedulable)

#cordon #unschedulable

Prevent the Kubernetes scheduler from assigning new pods to the target node.

$kubectl cordon node-1
modifies Cluster Admin

Switch Active Kubeconfig Cluster Context

#context #kubeconfig #auth

Switch your active kubectl context between dev, staging, and production clusters.

$kubectl config use-context prod-cluster-admin

Pro-Tips for Daily CLI Operations

1. Fast Namespace Switching

Instead of continuously passing -n <namespace> to every single kubectl command, set your context namespace permanently for the current shell session:

# Switch default namespace for all subsequent commands
kubectl config set-context --current --namespace=my-production-ns

# Verify current active namespace and context
kubectl config get-contexts

Or install kubens / kubectx from ahmetb/kubectx for instant switching:

kubens my-production-ns

2. Streamlining Command Aliases

Boost your terminal productivity by configuring recommended aliases in your ~/.bashrc or ~/.zshrc:

# Essential Kubernetes Aliases
alias k="kubectl"
alias kgp="kubectl get pods -o wide"
alias kgs="kubectl get svc"
alias kgd="kubectl get deployments"
alias kl="kubectl logs -f --tail=100"
alias kx="kubectl exec -it"
alias kdp="kubectl describe pod"

# Essential Docker Aliases
alias d="docker"
alias dps="docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'"
alias dpa="docker ps -a"
alias dlog="docker logs -f --tail 100"
alias dcp="docker compose"

3. Safely Debugging Distroless & Scratch Containers

Production containers built without shells or diagnostic binaries can be inspected using Kubernetes Ephemeral Containers:

# Attach an interactive netshoot diagnostic container to a live pod
kubectl debug -it <pod-name> -n <namespace> \
  --image=nicolaka/netshoot \
  --target=<container-name>

This injects common networking and debugging tools (curl, tcpdump, dig, iperf, strace, netstat) into the target pod's network and process namespaces without modifying the production image itself.


Next Steps