Kubernetes Command Cheat Sheet
This is the list of commands that I often use.
A quick reference for managing and troubleshooting Kubernetes clusters.
# List all name spacees
kubectl get pods --all-namespaces
# Check logs of the pod. Copy the corresponding ns and pod
kubectl logs -n <namespace-name> <pod>
π¦ Pods
List all pods in the current namespace:
kubectl get pods
List pods in a specific namespace:
kubectl get pods -n <namespace-name>
List pods in all namespaces:
kubectl get pods --all-namespaces
Describe details of a specific pod:
kubectl describe pod <pod-name>
π Services
List all services in the current namespace:
kubectl get services
List services in a specific namespace:
kubectl get services -n <namespace-name>
List all services across all namespaces:
kubectl get services --all-namespaces
πͺ΅ Logs
View logs from a specific pod:
kubectl logs <pod-name>
View logs for a specific container in a multi-container pod:
kubectl logs <pod-name> -c <container-name>
Follow logs in real-time (stream logs):
kubectl logs -f <pod-name>
Get logs from a pod selected by label:
kubectl logs -l app=<service-name>
π» Exec / SSH into Pods
Open an interactive shell inside a pod (like SSH):
kubectl exec -it <pod-name> -- /bin/bash
If bash is unavailable (e.g., alpine, busybox):
kubectl exec -it <pod-name> -- /bin/sh
Exec into a specific container in a pod:
kubectl exec -it <pod-name> -c <container-name> -- /bin/bash
π§ Nodes
List all nodes:
kubectl get nodes
List nodes with IPs and status:
kubectl get nodes -o wide
Describe details of a specific node:
kubectl describe node <node-name>