☸️
kubectl Cheat Sheet
Essential Kubernetes commands — pods, logs, exec, rollout, and debugging.
Related: kubectl · kubernetes · helm · minikube
Cluster & context
| Command | Description | |
|---|---|---|
kubectl config get-contexts | List kubeconfig contexts | |
kubectl config use-context <name> | Switch cluster context | |
kubectl cluster-info | API server and services URL | |
kubectl get nodes -o wide | Node status and IPs |
Workloads
| Command | Description | |
|---|---|---|
kubectl get pods -A | All pods in all namespaces | |
kubectl get deploy,svc,ingress -n <ns> | Common resources in namespace | |
kubectl describe pod <pod> -n <ns> | Events and container state | |
kubectl logs <pod> -n <ns> -f | Stream container logs | |
kubectl logs <pod> -c <container> --previous | Logs from crashed container | |
kubectl exec -it <pod> -n <ns> -- /bin/sh | Shell into running pod |
Apply & rollout
| Command | Description | |
|---|---|---|
kubectl apply -f deployment.yaml | Create or update resources | |
kubectl apply -k overlays/prod/ | Apply Kustomize overlay | |
kubectl rollout status deploy/<name> | Wait for rollout to finish | |
kubectl rollout undo deploy/<name> | Rollback to previous revision | |
kubectl rollout history deploy/<name> | List revision history | |
kubectl delete -f deployment.yaml | Remove resources from file |
Debug
| Command | Description | |
|---|---|---|
kubectl get events -n <ns> --sort-by='.lastTimestamp' | Recent cluster events | |
kubectl port-forward svc/<name> 8080:80 | Local access to a service | |
kubectl top pods -n <ns> | CPU/memory (needs metrics-server) |