The kubectl Commands You Actually Use Daily
By Prabath Thalangama· October 24, 2026· 3 min read
#kubernetes#kubectl#reference
Introduction¶
kubectl has hundreds of options. Day to day you use a small, stable set. This
is that set, grouped by what you're trying to do.
Context and namespace¶
kubectl config get-contexts
kubectl config use-context prod
kubectl config set-context --current --namespace=team-a # stop typing -n
# kubens / kubectx (krew or standalone) are worth installing
kubectl ctx # switch context
kubectl ns # switch namespace
Looking at things¶
kubectl get pods -o wide # + node, IP
kubectl get pods -w # watch
kubectl get pods -A # all namespaces
kubectl get pods -l app=api,tier=backend # label selector
kubectl get pods --field-selector status.phase=Running
kubectl get all -n team-a # pods/svc/deploy/rs (not everything, despite the name)
kubectl describe pod mypod # Events at the bottom
kubectl get events --sort-by=.lastTimestamp -A | tail -30
Output formats¶
kubectl get pod mypod -o yaml
kubectl get pod mypod -o jsonpath='{.status.podIP}'
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
kubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName,RESTARTS:.status.containerStatuses[0].restartCount
kubectl get nodes -o json | jq '.items[].status.capacity'
Logs and shells¶
kubectl logs mypod -f
kubectl logs mypod -c sidecar --previous # crashed container's logs
kubectl logs -l app=api --tail=100 --prefix # aggregate across pods
kubectl logs deploy/api # a pod of the deployment
kubectl exec -it mypod -- sh
kubectl exec mypod -- env
kubectl debug -it mypod --image=nicolaka/netshoot --target=app # ephemeral debug container
kubectl cp mypod:/var/log/app.log ./app.log
Resource usage¶
kubectl top nodes
kubectl top pods -A --sort-by=memory
kubectl describe node node-1 | grep -A10 'Allocated resources'
Rollouts¶
kubectl rollout status deploy/api
kubectl rollout history deploy/api
kubectl rollout undo deploy/api # to previous
kubectl rollout undo deploy/api --to-revision=3
kubectl rollout restart deploy/api # re-create pods (pick up new ConfigMap, etc.)
kubectl scale deploy/api --replicas=5
Changing things safely¶
kubectl apply -f manifest.yaml
kubectl apply -f manifest.yaml --dry-run=server # validate against the API, no change
kubectl diff -f manifest.yaml # what would change
kubectl edit deploy/api # opens $EDITOR
kubectl patch deploy/api --type=merge -p '{"spec":{"replicas":3}}'
kubectl set image deploy/api api=myrepo/api:v2.1.0
kubectl label pod mypod team=a --overwrite
kubectl annotate ...
Generating manifests¶
kubectl create deployment api --image=myrepo/api:v1 --dry-run=client -o yaml > deploy.yaml
kubectl create job --from=cronjob/nightly manual-run-1
kubectl run tmp --rm -it --image=busybox --restart=Never -- sh
Verification and troubleshooting¶
kubectl api-resources # every resource type + short name + apiGroup
kubectl explain deployment.spec.strategy # field docs, offline
kubectl auth can-i create deployments
kubectl get --raw /healthz
kubectl version --short
kubectl get alldidn't show my ConfigMap / Ingress / PVC —allis a curated shortlist. Query the type explicitly orkubectl get $(kubectl api-resources --verbs=list -o name | paste -sd,)for truly everything.- jsonpath returns nothing — the field is missing on that object, or you
need
{range .items[*]}...{end}for a list. Test the path against-o json | jq. execfails "cannot exec in a completed pod" — the pod'sTerminated. Uselogs --previous, orkubectl debug.kubectl topsays "Metrics API not available" — metrics-server not installed.- Edits via
kubectl editrevert — a controller (Deployment, operator, Argo/Flux) owns the object and reconciles it back. Edit the source. - Slow commands — huge cluster + client-side filtering. Use
--field-selector/-lserver-side, raise--chunk-size.
Related tools and reading¶
- On-site: YAML validator, JSON formatter.
- Related posts: Kubernetes RBAC: Roles and Bindings, Debugging CrashLoopBackOff.
Related tools
Stuck on something this site can't fix?Reach out to Prabath directly on LinkedIn.More in Docker & Kubernetes
Docker & Kubernetes· 4 min read
StatefulSets Explained
StatefulSets give pods sticky names, sticky storage, and ordered operations — what databases and clustered apps need. Here's how each guarantee works.
October 24, 2026Docker & Kubernetes· 3 min read
Persistent Volumes and Claims, Explained
PVC is a request, PV is the fulfilled storage, StorageClass is the factory. Most 'Pending PVC' problems are an access-mode or provisioner mismatch.
October 24, 2026Docker & Kubernetes· 3 min read
Kubernetes Jobs and CronJobs
A Job runs pods until they succeed; a CronJob creates Jobs on a schedule. Here's parallelism, retry limits, the missed-schedule trap, and history cleanup.
October 24, 2026