After this lesson, you will be able to: Use kubectl confidently: inspect cluster state, follow logs, exec into Pods, describe failures, debug issues.
kubectl is the daily-driver CLI for K8s. Master 15 commands and you can debug 90% of production issues.
Your first commands when you SSH into a cluster you've never seen.
kubectl cluster-info # API server endpointskubectl get nodes # cluster nodeskubectl get nodes -o wide # with internal IPs and OSkubectl get namespaces # ns ; namespaceskubectl config current-context # which cluster am I onkubectl config get-contexts # all configured clusterskubectl config use-context my-prod # switch
These return JSON-ish lists; combine with -o for shapes.
kubectl get pods # default namespacekubectl get pods -A # ALL namespaceskubectl get pods -n kube-system # specific namespacekubectl get pods -l app=myapp # filter by labelkubectl get pods -o wide # show node + IPkubectl get pods -w # watch (live updates)kubectl get deployments,services,ingress -n productionkubectl get all -n production # one-shot
Describe + logs + exec, the daily-driver triad.
# describe: full event history + statuskubectl describe pod myapp-abc123 -n production# Look at the Events: section at the bottom; usually tells you why a Pod is stuck.# Logskubectl logs myapp-abc123 # current logskubectl logs myapp-abc123 --previous # logs from the PREVIOUS crashed containerkubectl logs -f myapp-abc123 # followkubectl logs -l app=myapp --tail=100 # last 100 lines across all matching pods# Exec into a running Podkubectl exec -it myapp-abc123 -- bash# Inside: same as docker exec; explore filesystem, run commands, etc.# Run a one-shot debugging Podkubectl run -it --rm debug --image=nicolaka/netshoot --restart=Never -- bash
Modifying cluster state.
kubectl apply -f myapp.yaml # create or update from filekubectl apply -f k8s/ # all YAMLs in a directorykubectl delete -f myapp.yaml # delete what's in the filekubectl edit deployment myapp # live-edit YAML (drops you in $EDITOR)kubectl scale deployment myapp --replicas=10kubectl rollout status deployment/myapp # is the rollout donekubectl rollout undo deployment/myapp # rollback to previous version
Forgetting the namespace. `kubectl get pods` in `default` is empty; the app's in `production`. Always check `-n`. Skipping `kubectl describe` and jumping to logs. Most failures are visible in the Events section. `kubectl edit` in production for permanent changes. Edits don't persist back to your git repo; the next CI deploy overwrites. Forgetting `--previous` on logs after a crash. The current container has fresh logs; the crashed one has the real error. Running `kubectl delete -f` on the wrong context. Always verify `current-context` before destructive operations.
Pick the order.
Sign in and purchase access to unlock this lesson.