All Cheat Sheets
kubectl
kubectl commands for contexts, pods, deployments, rollouts, logs, debugging, port-forwarding and node maintenance.
Contexts & configuration
Show merged kubeconfig
kubectl config viewList contexts
kubectl config get-contextsShow current context
kubectl config current-contextSwitch context
kubectl config use-context <context>Set default namespace for current context
kubectl config set-context --current --namespace=<namespace>Check client and server version
kubectl versionViewing resources
List pods
kubectl get podsPods with node and IP
kubectl get pods -o widePods in all namespaces
kubectl get pods --all-namespacesShort form: -AGet a resource as YAML
kubectl get pod <pod> -o yamlDescribe a pod (events, status)
kubectl describe pod <pod>Filter by label
kubectl get pods -l app=<name>Filter by field
kubectl get pods --field-selector=status.phase=RunningShow labels
kubectl get pods --show-labelsEvents, oldest first
kubectl get events --sort-by=.metadata.creationTimestampOnly warning events
kubectl events --types=WarningSort pods by restart count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'List all resource types
kubectl api-resourcesField docs for a resource
kubectl explain podsCreating & applying
Apply a manifest
kubectl apply -f ./manifest.yamlApply every manifest in a directory
kubectl apply -f ./dirPreview changes before applying
kubectl diff -f ./manifest.yamlCreate a deployment
kubectl create deployment nginx --image=nginxGenerate YAML without creating
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yamlCreate a one-off job
kubectl create job hello --image=busybox:1.28 -- echo "Hello World"Deployments & rollouts
Update a container image
kubectl set image deployment/<name> <container>=<image>:<tag>Watch rollout progress
kubectl rollout status -w deployment/<name>Rollout history
kubectl rollout history deployment/<name>Roll back to previous revision
kubectl rollout undo deployment/<name>Roll back to a specific revision
kubectl rollout undo deployment/<name> --to-revision=2Restart all pods of a deployment
kubectl rollout restart deployment/<name>Scale a deployment
kubectl scale --replicas=3 deployment/<name>Autoscale between limits
kubectl autoscale deployment <name> --min=2 --max=10Logs & debugging
Pod logs
kubectl logs <pod>Stream logs
kubectl logs -f <pod>Logs of one container
kubectl logs <pod> -c <container>Logs of the previous (crashed) container
kubectl logs <pod> --previousLogs from a deployment's pod
kubectl logs deploy/<name>Shell into a pod
kubectl exec --stdin --tty <pod> -- /bin/shRun one command in a pod
kubectl exec <pod> -- ls /Attach a debug container
kubectl debug <pod> -it --image=busybox:1.28Throwaway interactive pod
kubectl run -i --tty busybox --image=busybox:1.28 -- shPod CPU/memory usage
kubectl top podNeeds metrics-server in the clusterNetworking & files
Forward a local port to a pod
kubectl port-forward <pod> 5000:6000Forward to a service
kubectl port-forward svc/<service> 5000Expose a deployment as a service
kubectl expose deployment <name> --port=80 --target-port=8000Copy a file into a pod
kubectl cp /tmp/foo <pod>:/tmp/barCopy a file out of a pod
kubectl cp <namespace>/<pod>:/tmp/foo /tmp/barLabels, deleting & nodes
Add a label
kubectl label pods <pod> env=prodRemove a label
kubectl label pods <pod> env-Delete resources from a file
kubectl delete -f ./manifest.yamlDelete by label
kubectl delete pods,services -l app=<name>Mark node unschedulable
kubectl cordon <node>Drain a node for maintenance
kubectl drain <node>Make node schedulable again
kubectl uncordon <node>Node CPU/memory usage
kubectl top nodeKeep the references coming
One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.

