kubectl config get-contexts
kubectl config use-context prod
kubectl cluster-info
kubectl get nodes -o wide
kubectl get ns
kubectl config set-context --current --namespace=staging
kubectl get pods -n app
kubectl get svc,deploy,nodes
kubectl get pods -o wide
kubectl describe pod web-7c9d-xk2
kubectl get pods -l app=web
kubectl label pod web-7c9d-xk2 tier=frontend
kubectl apply -f deployment.yaml
kubectl create deployment web --image=nginx
kubectl scale deployment web --replicas=4
kubectl autoscale deployment web --min=2 --max=10 --cpu-percent=70
kubectl rollout status deployment/web
kubectl rollout undo deployment/web
kubectl rollout history deployment/web
kubectl logs web-7c9d-xk2
kubectl logs web-7c9d-xk2 -f
kubectl logs web-7c9d-xk2 --previous
kubectl exec -it web-7c9d-xk2 -- /bin/sh
kubectl port-forward pod/web-7c9d-xk2 8080:80
kubectl cp web-7c9d-xk2:/var/log/app.log ./app.log
kubectl expose deployment web --port=80 --target-port=8080
kubectl get endpoints web
kubectl create configmap app-cfg --from-file=app.conf
kubectl describe configmap app-cfg
kubectl create secret generic db-cred --from-literal=password=changeme
| Symptom | Likely Cause |
|---|---|
| CrashLoopBackOff | app exits on start — check logs --previous |
| ImagePullBackOff | wrong tag, private registry auth, or typo'd image name |
| Pending | no node has enough CPU/mem, or unmet nodeSelector/taint |
| OOMKilled | container exceeded its memory limit |
| Service has no traffic | selector labels don't match pod labels |
| 0/1 Ready | readiness probe failing — check the probe path/port |
| Command | Purpose |
|---|---|
| kubectl get events --sort-by=.lastTimestamp | debug cluster-wide recent events |
| kubectl top pods | live CPU/memory usage (needs metrics-server) |
| kubectl apply -f x.yaml --dry-run=client | safe validate without applying |
| kubectl delete pod x --grace-period=0 --force | destructive skip graceful termination |
| kubectl explain pod.spec.containers | inline field documentation |
| kubectl get pod x -o yaml | full resource definition as applied |