---
## Context
Kubernetes has a large surface area, but day-to-day operations rely on a **small, repeatable set of kubectl commands**.
This cheatsheet emphasizes:
- inspection over modification
- safety before speed
- commands that scale from dev clusters to production
It’s meant to be referenced, not memorized.
---
View current context:
kubectl config current-contextList contexts:
kubectl config get-contextsSwitch context:
kubectl config use-context my-contextAlways confirm context before making changes—many incidents start here.
List namespaces:
kubectl get nsSet a default namespace for the current context:
kubectl config set-context --current --namespace=my-namespaceExplicit namespaces reduce accidental cross-environment changes.
List pods:
kubectl get podsList pods with more detail:
kubectl get pods -o wideDescribe a pod:
kubectl describe pod my-podView pod logs:
kubectl logs my-podFollow logs:
kubectl logs -f my-podLogs and describe usually tell you more than guessing.
Execute a shell:
kubectl exec -it my-pod -- /bin/shFor multi-container pods:
kubectl exec -it my-pod -c my-container -- /bin/shKnow which container you’re debugging.
List deployments:
kubectl get deploymentsDescribe a deployment:
kubectl describe deployment my-deploymentCheck rollout status:
kubectl rollout status deployment my-deploymentRestart a deployment:
kubectl rollout restart deployment my-deploymentRollouts provide safer change visibility than manual restarts.
List services:
kubectl get svcDescribe a service:
kubectl describe svc my-serviceView endpoints:
kubectl get endpoints my-serviceService issues are often endpoint issues.
List nodes:
kubectl get nodesDescribe a node:
kubectl describe node my-nodeCheck node resource usage:
kubectl top nodeNode health underpins everything else.
Check pod resource usage:
kubectl top podFor a specific namespace:
kubectl top pod -n my-namespaceResource pressure explains many “random” failures.
View recent events:
kubectl get events --sort-by=.metadata.creationTimestampEvents often explain:
- scheduling failures
- image pull issues
- permission problems
They’re one of the most underused debugging tools.
Apply a manifest:
kubectl apply -f file.yamlDry-run before applying:
kubectl apply -f file.yaml --dry-run=clientView rendered resources:
kubectl get -f file.yamlPrefer apply over imperative commands for repeatability.
Delete by name:
kubectl delete pod my-podDelete from a manifest:
kubectl delete -f file.yamlDeletion is irreversible—confirm scope first.
Common workflow:
kubectl getkubectl describekubectl logskubectl execkubectl get events
Skipping steps usually costs time.
- Alias frequently used commands (
k=kubectl) - Always know your context and namespace
- Read before you write
- Prefer inspection over intervention
- Let the cluster tell you what’s wrong
Kubernetes is verbose—listen to it.
- kubectl is primarily an inspection tool
- A small command set covers most operational needs
- Events and describe output are critical
- Context mistakes cause real incidents
- Calm, repeatable workflows beat heroics
Comfort with kubectl turns Kubernetes from intimidating to manageable.