Tools
kubectl Cheat Sheet — Kubernetes Commands Reference
The kubectl commands you use daily to inspect, deploy, and debug workloads on a Kubernetes cluster.
Put it into practice with the matching tool.
Convert YAML and JSON →Advertisement
Contexts and namespaces
kubectl config get-contextsList clusters/contextskubectl config use-context nameSwitch clusterkubectl config set-context --current --namespace=appChange the default namespace-n app / -ATarget one namespace / all namespacesViewing resources
kubectl get podsList pods (also deploy, svc, ingress, nodes)kubectl get pods -o wideInclude node and IPkubectl get pod p -o yamlFull resource definitionkubectl describe pod pDetails and recent events — first stop when debuggingkubectl get events --sort-by=.lastTimestampRecent cluster eventskubectl top podsCPU and memory use (needs metrics-server)Logs and access
kubectl logs -f pFollow a pod's logskubectl logs p --previousLogs from the crashed previous containerkubectl logs deploy/web -c appLogs from a deployment's pod, one containerkubectl exec -it p -- shOpen a shell in a containerkubectl port-forward svc/web 8080:80Reach a service on localhost:8080kubectl cp p:/path ./localCopy files out of a podDeploying
kubectl apply -f manifest.yamlCreate or update resources from a filekubectl apply -k ./overlayApply a Kustomize directorykubectl diff -f manifest.yamlPreview what apply would changekubectl delete -f manifest.yamlDelete the resources in a filekubectl create deploy web --image=nginx --dry-run=client -o yamlGenerate a manifest skeletonScaling and rollouts
kubectl scale deploy/web --replicas=3Change the replica countkubectl set image deploy/web app=img:v2Update a container imagekubectl rollout status deploy/webWatch a rollout finishkubectl rollout undo deploy/webRoll back to the previous versionkubectl rollout restart deploy/webRestart all pods gracefullyPod status clues
CrashLoopBackOffContainer keeps exiting — check logs --previousImagePullBackOffWrong image name/tag or missing registry credentialsPendingNot scheduled — not enough resources or no matching nodeOOMKilledExceeded its memory limit