k8s-debug commands
27 commands, each with a one-line explanation. Click a command to copy it, or its title for details.
Commands 27 shown
-
kubectl debug -it <pod> --image=nicolaka/netshoot -n <ns>Attach a debug container (netshoot) to a running pod — shares PID/net namespaces
-
kubectl top nodesCPU and memory per node (requires metrics-server)
-
kubectl top pods -A --sort-by=memoryMemory-sorted pod usage across all namespaces — find the hungry ones
-
kubectl get cm <name> -n <ns> -o jsonpath='{.data}'Print just the data field; pipe to python -m json.tool for formatting
-
kubectl get secret <name> -n <ns> -o jsonpath='{.data}' | python3 -c "import sys,json,base64; [print(k,'=',base64.b64decode(v).decode()) for k,v in json.load(sys.stdin).items()]"Dump and base64-decode all fields in a k8s Secret
-
kubectl api-resources --verbs=list --namespaced -o name | xargs -I{} kubectl get {} -n <ns> --ignore-not-foundEnumerate every resource type in a namespace — useful for auditing
-
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}\t{.metadata.name}\t{.status.phase}\n{end}'Extract specific fields from k8s API objects without jq
-
kubectl debug -it mypod --image=busybox --target=appAttach an ephemeral debug container to a running pod
-
kubectl debug node/my-node -it --image=ubuntuGet privileged shell on a cluster node via debug pod
-
kubectl exec -it mypod -c sidecar-name -- /bin/shOpen shell in a specific container of a multi-container pod
-
kubectl get pod mypod -o jsonpath='{range .spec.containers[*]}{.name}{"\t"}{.resources}{"\n"}{end}'Show resource requests and limits for each container
-
kubectl describe node my-node | grep -A5 'Conditions:'Check node conditions: Ready, MemoryPressure, DiskPressure
-
kubectl top pods -A --sort-by=memory | head -20Top 20 pods sorted by memory consumption
-
kubectl get events -n mynamespace --field-selector involvedObject.name=mypod --watchStream events for a specific pod
-
kubectl cp mynamespace/mypod:/var/log/app.log ./app.logDownload a file from a running container
-
kubectl get po -A --sort-by='.status.containerStatuses[0].restartCount' | tail -20Rank pods cluster-wide by restart count to spot crash loops fast
-
kubectl get po -A -o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{" "}{.status.containerStatuses[*].lastState.terminated.reason}{"\n"}{end}' | grep OOMKilledList pods whose last container exit was OOMKilled across all namespaces
-
kubectl get po -A --field-selector=status.phase=Pending -o name | xargs -I{} kubectl describe {} -n <ns> | grep -A3 FailedSchedulingExtract FailedScheduling reasons for every Pending pod (taints, resources, affinity)
-
kubectl describe node <node> | grep -A12 Conditions; ssh <node> 'journalctl -u kubelet -n 100 --no-pager'Read node Conditions then tail kubelet journal to find why node is NotReady
-
kubectl get events -n <ns> --field-selector reason=Failed -o wide | grep -i 'pull\|manifest\|unauthorized'Surface registry pull failures: bad tag, missing imagePullSecret, or rate limit
-
kubectl get po -A | grep Evicted | awk '{print $2" -n "$1}' | xargs -L1 kubectl delete poBulk-delete all Evicted pods left behind by node-pressure eviction
-
kubectl patch po <pod> -n <ns> -p '{"metadata":{"finalizers":null}}' --type=merge; kubectl delete po <pod> -n <ns> --grace-period=0 --forceClear finalizers to unstick a pod hung in Terminating; note: confirm node is gone first
-
kubectl get --raw /api/v1/nodes/<node>/proxy/stats/summary | jq '.pods[] | {name:.podRef.name, mem:.memory.workingSetBytes}'Pull live per-pod memory from kubelet Summary API, bypassing metrics-server
-
kubectl debug node/<node> -it --image=nicolaka/netshoot -- conntrack -SCheck per-CPU conntrack drops/insert_failed; nf_conntrack table exhaustion drops packets
-
kubectl run dnstest --rm -it --image=nicolaka/netshoot --restart=Never -- dig +short <name>.<ns>.svc.cluster.localResolve a Service FQDN from an ephemeral pod to isolate CoreDNS vs app DNS issues
-
kubectl events --for pod/<pod> -n <ns> --types=WarningStream only Warning events scoped to one pod in chronological order; modern: replaces get events filter
-
kubectl logs <pod> -n <ns> -c <name> --previous --timestamps --tail=200Tail the crashed container's prior instance logs to catch the pre-restart stack trace
no commands match — try a different search