█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/DevOps and Infrastructure/Kubernetes/kubectl
40 minIntermediate

kubectl

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.

Prerequisites:Core Kubernetes Concepts

Cluster inspection

Your first commands when you SSH into a cluster you've never seen.

tsx
kubectl cluster-info # API server endpoints
kubectl get nodes # cluster nodes
kubectl get nodes -o wide # with internal IPs and OS
kubectl get namespaces # ns ; namespaces
kubectl config current-context # which cluster am I on
kubectl config get-contexts # all configured clusters
kubectl config use-context my-prod # switch

Workload inspection

These return JSON-ish lists; combine with -o for shapes.

tsx
kubectl get pods # default namespace
kubectl get pods -A # ALL namespaces
kubectl get pods -n kube-system # specific namespace
kubectl get pods -l app=myapp # filter by label
kubectl get pods -o wide # show node + IP
kubectl get pods -w # watch (live updates)
kubectl get deployments,services,ingress -n production
kubectl get all -n production # one-shot

Debugging individual workloads

Describe + logs + exec, the daily-driver triad.

tsx
# describe: full event history + status
kubectl describe pod myapp-abc123 -n production
# Look at the Events: section at the bottom; usually tells you why a Pod is stuck.
# Logs
kubectl logs myapp-abc123 # current logs
kubectl logs myapp-abc123 --previous # logs from the PREVIOUS crashed container
kubectl logs -f myapp-abc123 # follow
kubectl logs -l app=myapp --tail=100 # last 100 lines across all matching pods
# Exec into a running Pod
kubectl exec -it myapp-abc123 -- bash
# Inside: same as docker exec; explore filesystem, run commands, etc.
# Run a one-shot debugging Pod
kubectl run -it --rm debug --image=nicolaka/netshoot --restart=Never -- bash

Apply, edit, delete

Modifying cluster state.

tsx
kubectl apply -f myapp.yaml # create or update from file
kubectl apply -f k8s/ # all YAMLs in a directory
kubectl delete -f myapp.yaml # delete what's in the file
kubectl edit deployment myapp # live-edit YAML (drops you in $EDITOR)
kubectl scale deployment myapp --replicas=10
kubectl rollout status deployment/myapp # is the rollout done
kubectl rollout undo deployment/myapp # rollback to previous version

💡 k9s: the terminal UI everyone eventually installs

k9s wraps kubectl in a Vim-like terminal UI. Live updates of every object, single-keystroke navigation, filter by namespace / label / pod. Install: brew install k9s, scoop install k9s, or go install github.com/derailed/k9s@latest. Stick with raw kubectl for a few weeks first to learn the model; then add k9s and never look back.

Common mistakes only experienced engineers avoid

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.

Quick Check

Your Pod is in CrashLoopBackOff. What's your debug sequence?

Pick the order.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Core Concepts: Pods, Deployments, Services
Back to Kubernetes
Deployments in Depth→