Kubernetes Commands Cheat Sheet

Common Kubernetes commands: kubectl get, apply, delete, scale, rollout, port-forward and more, with notes for everyday cluster ops and troubleshooting.

CommandDescription
kubectl versionShow client and server version
kubectl cluster-infoShow cluster control-plane address
kubectl get nodesList cluster nodes (-o wide)
kubectl get podsList pods (-A all namespaces)
kubectl get servicesList services
kubectl get deploymentsList deployments
kubectl describe podShow pod details and events
kubectl logsShow pod logs (-f follow)
kubectl execRun a command in a container (-it)
kubectl apply -fCreate/update from a manifest
kubectl createCreate a resource imperatively
kubectl deleteDelete a resource (-f or name)
kubectl editEdit a resource live
kubectl scaleScale replica count
kubectl rollout statusShow rollout progress
kubectl rollout undoUndo a rollout
kubectl port-forwardForward a local port to a pod
kubectl exposeExpose a resource as a service
kubectl config get-contextsList kubeconfig contexts
kubectl config use-contextSwitch current context
kubectl top nodesShow node CPU/memory usage
kubectl top podsShow pod resource usage
kubectl cpCopy files between container and local
kubectl cordonMark a node unschedulable
kubectl uncordonMark a node schedulable
kubectl drainDrain a node for maintenance
kubectl get allList all resources in a namespace

Frequently Asked Questions

What is the difference between kubectl apply and create?

`apply` is declarative: it diffs the manifest against cluster state and makes incremental changes, safe to re-run and ideal for GitOps; `create` is imperative and errors on re-run.

How do I find why a pod keeps crashing?

First `kubectl describe pod <name>` to inspect Events and Last State (Exit Code, Reason); then `kubectl logs --previous` to see logs from the crashed container.

How do I port-forward to a pod for local debugging?

Use `kubectl port-forward pod/<name> 8080:80` to map local 8080 to the pod's 80, then hit `localhost:8080`—no Service exposure needed.

How do I roll back a failed rollout?

`kubectl rollout undo deployment/<name>` reverts to the previous revision; `kubectl rollout history deployment/<name>` lists revisions, and `--to-revision=N` targets a specific one.