Even if you don’t operate Kubernetes yourself, you will end up reading logs from a deployed service or working out why a pod won’t start. This page concentrates on reading and debugging.

Install

  brew install kubectl k9s
brew install kubectx        # context and namespace switching
  

Check your context first

  kubectl config get-contexts
kubectl config current-context
kubectx staging             # switch context
kubens my-namespace         # switch namespace
  

Running a command against production without realising you were pointed at it is the most common accident here. Putting the current context in your prompt prevents it (Starship’s kubernetes module does this).

Looking around

  kubectl get pods                      # current namespace
kubectl get pods -A                   # all namespaces
kubectl get pods -o wide              # with node and IP
kubectl get pods -w                   # watch changes live
kubectl get deploy,svc,ingress        # several resource types at once

kubectl describe pod <name>            # details including events (start here)
kubectl get pod <name> -o yaml         # the full definition
  

Logs and shells

  kubectl logs <pod>                     # logs
kubectl logs -f <pod>                  # follow
kubectl logs <pod> -c <container>      # when there are sidecars
kubectl logs <pod> --previous          # logs from before a restart (crash causes)
kubectl logs -l app=api --tail=100     # several pods by label

kubectl exec -it <pod> -- sh           # into the container
kubectl port-forward svc/api 8080:80   # reach it locally
  

--previous is almost always what you need when debugging CrashLoopBackOff.

Reading pod status

StatusMeaning and what to check
PendingNot scheduled. Resources or node selectors → Events in describe
ImagePullBackOffWrong image name or registry credentials
CrashLoopBackOffThe container keeps dying → logs --previous
OOMKilledExceeded the memory limit → adjust limits
Running but requests failCheck the readiness probe and the service selector

k9s — a terminal dashboard

  k9s
  
KeyAction
:pods :deploy :svcSwitch resource type
/textFilter
lLogs
dDescribe
sShell in
Ctrl+DDelete
:ctx / :nsSwitch context or namespace
?Help

It collapses the get → describe → logs loop into single keystrokes. If you look at clusters often, start here rather than with kubectl.

Safety rules

  • Always dry-run a delete first: --dry-run=client.
  • In a production context, run kubectl diff -f before kubectl apply.
  • Editing a live resource with edit gets overwritten by the next deploy. Fix the manifest repository instead.

Next

To automate the deploy itself → GitHub Actions

Last updated 19 Aug 2026, 00:00 UTC. history