kubectl Cheat Sheet (Kubernetes CLI)¶
A practical kubectl cheat sheet for day-to-day debugging and operations.
Setup & context¶
Show current context and switch clusters:
kubectl config current-context
kubectl config get-contexts
kubectl config use-context <context-name>
Set a default namespace for the current context:
Quick “what’s running?”¶
kubectl get nodes -o wide
kubectl get ns
kubectl get pods -A
kubectl get pods -n <ns> -o wide
kubectl get deploy,rs,svc,ing -n <ns>
Watch changes:
Describe & events (first stop for debugging)¶
kubectl describe pod <pod> -n <ns>
kubectl describe deploy <deploy> -n <ns>
kubectl get events -n <ns> --sort-by=.metadata.creationTimestamp
Logs¶
Single container:
Specific container in a multi-container pod:
Previous crash:
Exec / shell in a container¶
Port-forward¶
Pod:
Service:
Apply / rollout¶
Apply manifests:
Deployment rollout status:
Rollback:
Scale & restart¶
Scale replicas:
Restart a deployment (forces new ReplicaSet):
Delete safely¶
Delete one resource:
Delete a namespace (careful):
YAML/JSON output + common JSONPath¶
Get full YAML:
Common JSONPath snippets:
# Image(s) used by a deployment
kubectl get deploy/<deploy> -n <ns> -o jsonpath='{.spec.template.spec.containers[*].image}{"\n"}'
# Pod phase + node
kubectl get pod/<pod> -n <ns> -o jsonpath='{.status.phase}{" on "}{.spec.nodeName}{"\n"}'
Troubleshooting patterns¶
Pod stuck Pending: - Check node capacity / taints / tolerations / PVC binding.
CrashLoopBackOff:
- Check logs + --previous, then events.
ImagePullBackOff: - Check image name/tag and registry credentials.
- Placeholder content for validating category + tags rendering.