All Cheat SheetsDevOps
Kubernetes kubectl CLI Cheat Sheet
Essential kubectl commands for cluster inspection, pods, deployments, services, debugging, and config
Cluster & Context Management
Inspect cluster state and switch namespaces/contexts
Display current kubeconfig context
kubectl config current-contextSwitch to different context
kubectl config use-context <cluster-name>Set default namespace for current context
kubectl config set-context --current --namespace=<ns>Display cluster info and endpoints
kubectl cluster-infoPod Management & Debugging
List, inspect, log, and troubleshoot active pods
List pods with IP and node placement
kubectl get pods -o wide -n <namespace>Tail real-time logs from pod container
kubectl logs -f <pod-name> -c <container-name> --tail=100Interactive shell inside running pod
kubectl exec -it <pod-name> -- /bin/shDescribe pod events & failure reasons
kubectl describe pod <pod-name>Forward local port to remote pod
kubectl port-forward pod/<pod-name> 8080:80Deployments, Services & Rollouts
Manage application workloads and traffic routing
Scale deployment replicas
kubectl scale deployment/<app> --replicas=3Trigger zero-downtime rolling restart
kubectl rollout restart deployment/<app>Check rollout status / history
kubectl rollout status deployment/<app>
kubectl rollout history deployment/<app>Rollback to previous revision
kubectl rollout undo deployment/<app>List all services and ClusterIPs
kubectl get svc -AResource Manifests & Cleanups
Apply manifest file or URL
kubectl apply -f ./deployment.yamlExtract resource manifest as clean YAML
kubectl get deployment/<app> -o yaml > app.yamlDelete all pods in Error or Evicted state
kubectl delete pods --field-selector=status.phase=Failed -ATop CPU and Memory resource usage
kubectl top nodes
kubectl top pods -A