Kubernetes Command Cheat Sheet
A clean and practical reference for managing and troubleshooting Kubernetes clusters.
These are the commands I use most often.
π¦ Pods (Inspect, Logs, Exec, Manage)
π List & Inspect Pods
kubectl get pods
kubectl get pods -n <namespace>
kubectl get pods --all-namespaces
kubectl describe pod <pod-name>
Pods on a specific node
kubectl get pods -A -o wide | grep <node>
Pod resource requests
kubectl get pods -n <ns> -o json | jq -r '.items[] |
"\(.metadata.name)\tCPU:\(.spec.containers[0].resources.requests.cpu)\tMEM:\(.spec.containers[0].resources.requests.memory)"'
Pod tolerations
kubectl get pods -n <ns> -o json | jq -r '.items[] |
"\(.metadata.name)\t\(.spec.tolerations | map(.key) | join(","))"'
Pod events
kubectl describe pod <pod> -n <ns> | grep -A 10 "Events:"
Pod resource usage (metrics-server)
kubectl top pods -n <ns>
πͺ΅ Logs
kubectl logs <pod>
kubectl logs <pod> -c <container>
kubectl logs -f <pod>
kubectl logs -l app=<label>
π» Exec / Shell Access
kubectl exec -it <pod> -- /bin/bash
kubectl exec -it <pod> -- /bin/sh
kubectl exec -it <pod> -c <container> -- /bin/bash
π§Ή Pod Management
kubectl delete pod <pod> -n <ns>
kubectl delete pod <pod> -n <ns> --force --grace-period=0
kubectl delete pod --all -n <ns>
kubectl delete pod -n <ns> -l key=value
π Services
kubectl get services
kubectl get services -n <namespace>
kubectl get services --all-namespaces
π§ Nodes (Inspect, Usage, Manage)
π Node Info
kubectl get nodes
kubectl get nodes -o wide
kubectl describe node <node>
Node labels, taints, instance type
kubectl get node <node> -o json | jq '.metadata.labels'
kubectl describe node <node> | grep Taints
kubectl get node <node> -o json | jq -r '.metadata.labels."node.kubernetes.io/instance-type"'
π Node Resource Usage
kubectl describe node <node> | grep -A 5 "Allocated resources"
kubectl top nodes
π Node Management (Cordon / Drain / Delete)
πΉ Cordon β stop scheduling new pods
kubectl cordon <node>
πΉ Drain β evict workloads safely
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data --force
πΉ Delete β remove node from Kubernetes
kubectl delete node <node> --force --grace-period=0
π Quick Comparison
| Action | Stops New Pods? | Evicts Pods? | Removes Node? | Use Case |
|---|---|---|---|---|
| cordon | βοΈ | β | β | Prepare for maintenance |
| drain | βοΈ | βοΈ | β | Safely remove workloads |
| delete | βοΈ | βοΈ (node gone) | βοΈ | Node is broken or gone |
π§± Storage (PVC)
List PVCs
kubectl get pvc -A
kubectl get pvc -n <namespace>
Describe a PVC
kubectl describe pvc <pvc-name> -n <namespace>
Check volume affinity issues
kubectl describe pod <pod> -n <ns> | grep -i volume
β Pod Disruption Budgets (PDB)
kubectl get pdb -A
kubectl get pdb -n <namespace>
kubectl describe pdb <pdb> -n <namespace>
π§ Useful Commands
Count pods on a node
kubectl get pods -A -o wide | grep <node> | wc -l
Count pods by namespace
kubectl get pods -A --no-headers | awk '{print $1}' | sort | uniq -c
List instance types in the cluster
kubectl get nodes -o json | jq -r \
'.items[].metadata.labels."node.kubernetes.io/instance-type"' | sort | uniq
Node β workload mapping
kubectl get nodes -o json | jq -r '.items[] |
"\(.metadata.name)\t\(.metadata.labels.workload // "none")\t\(.metadata.labels."node.kubernetes.io/instance-type")"'