kubectl config get-contexts | List every configured cluster context. |
kubectl config use-context <name> | Switch the active cluster. |
kubectl config set-context --current --namespace=<ns> | Set the default namespace so you can stop typing -n. |
kubectl cluster-info | Show the control plane and CoreDNS endpoints. |
kubectl api-resources | Every resource kind the cluster knows, with short names. |
kubectl explain deploy.spec.strategy | Inline schema documentation for any field path. |
kubectl get pods -o wide | Pods with node, pod IP, and nominated node columns. |
kubectl get all -n <ns> | The common workload kinds in one namespace. |
kubectl get pods -A --field-selector=status.phase!=Running | Everything that is not healthy, cluster wide. |
kubectl get pods --sort-by=.status.containerStatuses[0].restartCount | Rank pods by restart count — the fastest way to spot a crash loop. |
kubectl get pod <pod> -o jsonpath='{.spec.nodeName}' | Extract a single field for scripting. |
kubectl describe pod <pod> | Full state plus the Events that explain it. Read the bottom first. |
kubectl get events --sort-by=.lastTimestamp | Cluster events in chronological order. |
kubectl top pod --containers | Live CPU and memory per container (needs metrics-server). |
kubectl get endpointslices -l kubernetes.io/service-name=<svc> | The ready pod IPs actually behind a Service. |
kubectl logs <pod> --previous | Logs from the container instance that crashed, not the new one. |
kubectl logs -l app=web --prefix --all-containers -f | Follow logs from every pod matching a label. |
kubectl logs <pod> --since=15m --timestamps | Recent logs with timestamps attached. |
kubectl exec -it <pod> -- sh | Interactive shell inside a running container. |
kubectl exec <pod> -- env | sort | Dump the container environment without an interactive session. |
kubectl debug -it <pod> --image=nicolaka/netshoot --target=<container> | Ephemeral debug container sharing the pod namespaces. Works on distroless. |
kubectl port-forward svc/<name> 8080:80 | Tunnel a Service port to localhost through the API server. |
kubectl cp <pod>:/var/log/app.log ./app.log | Copy a file out of a container. |
kubectl auth can-i <verb> <resource> --as <user> | Check RBAC without trial and error. |
kubectl apply -f <file|dir> | Create or update via a three-way merge. The only one safe to repeat. |
kubectl diff -f <file> | Show exactly what applying would change on the live object. |
kubectl apply -f <file> --dry-run=server | Validate against the real API server without writing anything. |
kubectl scale deploy/<name> --replicas=5 | Change replica count immediately. |
kubectl set image deploy/<name> <container>=<image> | Trigger a rolling update to a new image. |
kubectl rollout status deploy/<name> --timeout=120s | Block until the rollout completes or times out. |
kubectl rollout restart deploy/<name> | Recreate every pod with no spec change, respecting surge limits. |
kubectl rollout undo deploy/<name> --to-revision=2 | Scale a previous ReplicaSet back up. |
kubectl label pod <pod> tier=canary --overwrite | Add or change a label in place. |
kubectl delete pod <pod> --grace-period=0 --force | Last resort for a stuck pod. Skips graceful shutdown. |
kubectl get nodes -o wide | Node status, roles, versions, and internal IPs. |
kubectl describe node <node> | Conditions, allocatable resources, and what is already claimed. |
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data | Evict workloads before maintenance. |
kubectl uncordon <node> | Mark a node schedulable again. |
kubectl taint node <node> key=value:NoSchedule | Repel pods that do not tolerate the taint. |