Skip to content

/cheatsheets/kubernetes/kubectl-cheat-sheet

kubectl cheat sheet: everyday Kubernetes commands

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Client Version: v1.37.1updated 2026-10-20
tool
Kubernetes
versions
kubectl 1.30+
os
any

The kubectl commands used every day, grouped by task. Add -n NAMESPACE to any command to target a namespace other than the current one, or -A to list across all namespaces.

Context and namespace

CommandDoes
kubectl config get-contextslist clusters/users in your kubeconfig
kubectl config use-context NAMEswitch cluster
kubectl config set-context --current --namespace=NSchange the default namespace
kubectl cluster-infoshow the API server address

Inspect

CommandDoes
kubectl get pods -o widepods with node and IP
kubectl get allcommon resources in the namespace
kubectl describe pod NAMEdetails and recent events (why a pod is Pending or crashing)
kubectl get events --sort-by=.lastTimestampevents, newest last
kubectl logs NAME [-c CONTAINER] [-f] [--previous]container logs; --previous for the crashed instance
kubectl top podsCPU and memory (needs metrics-server)
kubectl explain deployment.spec.strategyfield documentation from the API server

Change

CommandDoes
kubectl apply -f FILE_OR_DIRcreate or update from manifests
kubectl diff -f FILEshow what apply would change
kubectl scale deployment NAME --replicas=3scale
kubectl set image deployment/NAME CONTAINER=IMG:TAGupdate an image
kubectl rollout status deployment/NAMEwait for a rollout
kubectl rollout undo deployment/NAMEroll back to the previous revision
kubectl rollout restart deployment/NAMErestart all pods
kubectl delete -f FILEdelete what a manifest created

Debug

CommandDoes
kubectl exec -it NAME -- shshell in a running container
kubectl port-forward svc/NAME 8080:80reach a service from localhost:8080
kubectl debug -it NAME --image=busybox --target=CONTAINERephemeral debug container
kubectl cp NAME:/path ./localcopy files from a pod

Generate manifests offline

bash
kubectl create deployment web --image=nginx:1.29 --dry-run=client -o yaml | head -12
kubectl create cronjob backup --image=busybox:1.37 --schedule="0 3 * * *" --dry-run=client -o yaml | grep -E 'kind|schedule'

Output

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  strategy: {}
kind: CronJob
  schedule: 0 3 * * *

Output formats

-o yaml, -o json, -o name, -o wide, -o jsonpath='{.items[*].metadata.name}', and -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName.

Sources