Every Kubernetes task — deploying an application, checking why a pod crashed, or scaling a service — goes through one tool: kubectl. Memorizing its syntax from scratch is slow, which is why this kubectl commands cheat sheet collects the 30 commands administrators actually use every day. Each command in this kubectl commands cheat sheet is grouped by task and shown with a short explanation, so you can copy it straight into your terminal and adapt the names to your own cluster.
The examples assume you already have a working cluster. If you do not, follow our tutorial to install a Kubernetes cluster with kubeadm first, or use a local cluster for practice.
Getting Started with the kubectl Commands Cheat Sheet
These commands tell you what kubectl is connected to and what the cluster looks like:
# Show cluster connection details
kubectl cluster-info
# List all nodes and their status
kubectl get nodes
# Wide output: node IPs, OS image, kernel version
kubectl get nodes -o wide
# Check component versions
kubectl version
# Show your current context (cluster + user + namespace)
kubectl config current-context
# List all available contexts
kubectl config get-contexts
# Switch to another context
kubectl config use-context production
Working with Pods
Pods are the smallest unit in Kubernetes. These are the pod commands you will type most often:
# List pods in the current namespace
kubectl get pods
# List pods in ALL namespaces
kubectl get pods -A
# Watch pods as they change state in real time
kubectl get pods -w
# Full details about one pod: events, containers, IPs
kubectl describe pod web-7d9f8c6b5-x2abc
# Show logs of a pod
kubectl logs web-7d9f8c6b5-x2abc
# Logs of the previous (crashed) container instance
kubectl logs web-7d9f8c6b5-x2abc --previous
# Open a shell inside a running pod
kubectl exec -it web-7d9f8c6b5-x2abc -- /bin/sh
# Delete a pod (its Deployment will recreate it)
kubectl delete pod web-7d9f8c6b5-x2abc
Deployments and Scaling in This kubectl Commands Cheat Sheet
Deployments manage your application replicas. With these commands you create, update, and roll back releases:
# Create a deployment with 3 replicas
kubectl create deployment web --image=nginx --replicas=3
# List deployments
kubectl get deployments
# Scale up or down
kubectl scale deployment web --replicas=5
# Update the container image (triggers a rolling update)
kubectl set image deployment/web nginx=nginx:1.27
# Check rollout progress
kubectl rollout status deployment/web
# See rollout history
kubectl rollout history deployment/web
# Undo the last rollout
kubectl rollout undo deployment/web
Services and Networking Commands
# List services
kubectl get services
# Expose a deployment as a NodePort service
kubectl expose deployment web --port=80 --type=NodePort
# Forward a pod port to your machine (great for debugging)
kubectl port-forward pod/web-7d9f8c6b5-x2abc 8080:80
# List endpoints behind a service
kubectl get endpoints
Applying and Editing YAML
Real clusters are managed declaratively with YAML files:
# Create or update resources from a file
kubectl apply -f app.yaml
# Preview changes without applying (server-side dry run)
kubectl apply -f app.yaml --dry-run=server
# Generate YAML without creating anything
kubectl create deployment web --image=nginx --dry-run=client -o yaml > web.yaml
# Edit a live resource in your editor
kubectl edit deployment web
# Delete everything defined in a file
kubectl delete -f app.yaml
Namespaces
# List namespaces
kubectl get namespaces
# Create a namespace
kubectl create namespace staging
# Set the default namespace for your shell session
kubectl config set-context --current --namespace=staging
# Run a command in a specific namespace
kubectl get pods -n kube-system
Debugging and Troubleshooting Commands
When something breaks, this part of the kubectl commands cheat sheet earns its keep. For a deeper walkthrough of one specific failure mode, read our guide on how to troubleshoot CrashLoopBackOff pods.
# Events sorted by time — the first place to look
kubectl get events --sort-by=.metadata.creationTimestamp
# Resource usage per node
kubectl top nodes
# Resource usage per pod (needs metrics-server)
kubectl top pods
# Why is this pod not running? Check the Events section
kubectl describe pod
# Print a debug container into a stuck pod
kubectl debug -it --image=busybox --target=app
Useful kubectl Shortcuts and Aliases
Resource names have short forms that save a lot of typing:
po— pods,deploy— deployments,svc— servicesns— namespaces,no— nodes,cm— configmaps-A— all namespaces,-o wide— extra columns,-w— watch
Many administrators also add alias k=kubectl to their shell profile and enable autocompletion with source <(kubectl completion bash).
Conclusion
Bookmark this kubectl commands cheat sheet and keep it open while you work — after a few weeks of daily use, the core commands (get, describe, logs, apply, rollout) become muscle memory. For the complete reference, including every flag, consult the official kubectl reference documentation. The fastest way to learn is to break things on a test cluster: delete a pod, watch it come back, roll out a bad image, and roll it back. That hands-on loop is exactly what this cheat sheet is designed to support.