Kubernetes / kubectl Cheatsheet
Operate clusters from the command line. Most commands take -n <namespace> and --context <name>.
1 credit
Inspect
5 itemsAll resources in ns
kubectl get all -n <ns>Pods wide (show node)
kubectl get pods -o wideDescribe (events + spec)
kubectl describe pod <name>YAML export
kubectl get deploy <n> -o yamlCluster-wide resources
kubectl api-resources --namespaced=falseLogs & shell
5 itemsLogs (follow, last 100)
kubectl logs -f --tail=100 <pod>Logs of crashed container
kubectl logs <pod> -c <container> --previousExec into container
kubectl exec -it <pod> -- shPort-forward local → pod
kubectl port-forward svc/web 8080:80Copy files
kubectl cp <pod>:/path/in/pod ./localApply & scale
5 itemsApply manifest
kubectl apply -f deploy.yamlApply dir recursively
kubectl apply -R -f ./k8sScale deployment
kubectl scale deploy/web --replicas=5Rolling restart
kubectl rollout restart deploy/webRollback
kubectl rollout undo deploy/webContext & namespace
3 itemsList contexts
kubectl config get-contextsSwitch context
kubectl config use-context <name>Default namespace
kubectl config set-context --current --namespace=<ns>