The kubectl commands you reach for constantly: inspecting pods, logs, deployments, scaling, port-forwarding, contexts, and debugging a broken cluster. Copy-paste ready.
kubectl config get-contexts # list contexts
kubectl config current-context # which cluster am I on
kubectl config use-context my-cluster # switch context
kubectl config set-context --current --namespace=dev # default namespacekubectl get pods # pods in current namespace
kubectl get pods -A # all namespaces
kubectl get pods -o wide # with node + IP
kubectl get pods -w # watch live
kubectl get all # pods, services, deployments, etc.
kubectl get deploy,svc,ingress # multiple types at once
kubectl describe pod my-pod # full detail + events
kubectl get events --sort-by=.metadata.creationTimestampkubectl logs my-pod # logs
kubectl logs -f my-pod # follow
kubectl logs my-pod -c my-container # specific container
kubectl logs --previous my-pod # logs from the crashed instance
kubectl exec -it my-pod -- sh # shell into a pod
kubectl exec my-pod -- env # run one commandkubectl apply -f deploy.yaml # create/update from manifest
kubectl apply -f ./manifests/ # whole directory
kubectl edit deployment my-app # edit live (opens $EDITOR)
kubectl delete -f deploy.yaml
kubectl delete pod my-pod # delete one pod (it restarts if managed)
kubectl delete pods --all -n dev # all pods in a namespacekubectl scale deployment my-app --replicas=5
kubectl rollout status deployment my-app
kubectl rollout history deployment my-app
kubectl rollout undo deployment my-app # roll back to previous
kubectl rollout restart deployment my-app # restart all pods (rolling)kubectl port-forward svc/my-svc 8080:80 # localhost:8080 -> service
kubectl port-forward pod/my-pod 5432:5432 # straight to a podkubectl top nodes
kubectl top pods -Akubectl get ns
kubectl create namespace staging
kubectl create secret generic db --from-literal=password=s3cret
kubectl get secret db -o jsonpath='{.data.password}' | base64 -dkubectl get pods -A | grep -vE 'Running|Completed' # find unhealthy pods
kubectl describe pod my-pod | grep -A20 Events # why won't it start
kubectl get pod my-pod -o yaml # full spec
kubectl debug -it my-pod --image=busybox --target=app # ephemeral debug container| Task | Command |
|---|---|
| Watch pods | kubectl get pods -w |
| Follow logs | kubectl logs -f <pod> |
| Shell into pod | kubectl exec -it <pod> -- sh |
| Apply manifest | kubectl apply -f file.yaml |
| Scale | kubectl scale deploy <name> --replicas=N |
| Restart deployment | kubectl rollout restart deploy <name> |
| Roll back | kubectl rollout undo deploy <name> |
| Port-forward | kubectl port-forward svc/<svc> 8080:80 |
| Find broken pods | kubectl get pods -A | grep -v Running |
Maintained by the team at EchoGlobal. Hiring? See our curated lists of Top Kubernetes Developers, Top Docker Developers, and Top DevOps Engineers on GitHub, or hire pre-vetted talent in days.