kubectl Cheat Sheet
The kubectl command reference — get, describe, logs, exec, apply, and the everyday debugging flow.
Getting Started
6kubectl versionClient and server versions
kubectl cluster-infoControl-plane endpoints
kubectl get nodes -o wideNodes with addresses and versions
kubectl api-resourcesEvery resource type and short name
kubectl explain podsDocs for a resource inline
kubectl explain pod.spec.containersDrill into a nested field
Querying Resources
11kubectl get podsPod list in the current namespace
kubectl get pods -AAll namespaces
kubectl get pods -n NSSpecific namespace
kubectl get pods -l app=nginx,env=prodLabel selector
kubectl get pods -wWatch for changes
kubectl get pods -o wideNode and IP columns
kubectl get pods -o yamlFull manifest output
kubectl get deploy,sts,jobs -ASeveral kinds at once
kubectl get pod POD -o jsonpath='{.status.phase}'Extract one field
kubectl get pods --field-selector=status.phase=RunningFilter by field
kubectl get pods --sort-by=.metadata.nameSort output
Describe & Debug
12kubectl describe pod PODEvents, conditions, and state
kubectl describe node NODENode capacity and conditions
kubectl logs PODContainer logs
kubectl logs -f --tail=100 PODFollow the last 100 lines
kubectl logs deploy/NAMELogs across a deployment
kubectl logs POD -c SIDECARLogs for one container in a pod
kubectl logs POD --previousLogs from the crashed restart
kubectl exec -it POD -- /bin/shShell into the pod
kubectl exec POD -- envInspect the environment
kubectl debug node/NODE -it --image=nicolaka/netshootEphemeral debug container
kubectl cp NAMESPACE/POD:/path /localCopy files in or out
kubectl get events -A --sort-by=.lastTimestamp | tailRecent cluster events
Imperative Actions
8kubectl run POD --image=IMAGECreate a bare pod (testing)
kubectl create deployment NAME --image=IMAGECreate a deployment
kubectl scale --replicas=3 deployments/NAMEScale a workload
kubectl delete pod POD --grace-period=0 --forceForce-delete a stuck pod
kubectl cordon NODEMark unschedulable (draining)
kubectl drain NODE --ignore-daemonsetsEvict pods off a node
kubectl uncordon NODEAllow scheduling again
kubectl exec deploy/NAME -- touch /tmp/readyRun a command across replicas
Output Formats
6-o nameResource type/name only
-o jsonFull JSON
-o custom-columns=NAME:.metadata.nameCustom columns
-o wideAdditional columns
--no-headersSkip the header row
kubectl get pods --show-labelsInclude label columns