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.
| Command | Description |
|---|---|
| kubectl version | Show client and server version |
| kubectl cluster-info | Show cluster control-plane address |
| kubectl get nodes | List cluster nodes (-o wide) |
| kubectl get pods | List pods (-A all namespaces) |
| kubectl get services | List services |
| kubectl get deployments | List deployments |
| kubectl describe pod | Show pod details and events |
| kubectl logs | Show pod logs (-f follow) |
| kubectl exec | Run a command in a container (-it) |
| kubectl apply -f | Create/update from a manifest |
| kubectl create | Create a resource imperatively |
| kubectl delete | Delete a resource (-f or name) |
| kubectl edit | Edit a resource live |
| kubectl scale | Scale replica count |
| kubectl rollout status | Show rollout progress |
| kubectl rollout undo | Undo a rollout |
| kubectl port-forward | Forward a local port to a pod |
| kubectl expose | Expose a resource as a service |
| kubectl config get-contexts | List kubeconfig contexts |
| kubectl config use-context | Switch current context |
| kubectl top nodes | Show node CPU/memory usage |
| kubectl top pods | Show pod resource usage |
| kubectl cp | Copy files between container and local |
| kubectl cordon | Mark a node unschedulable |
| kubectl uncordon | Mark a node schedulable |
| kubectl drain | Drain a node for maintenance |
| kubectl get all | List 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.