Essential kubectl Commands for Comprehensive Kubernetes Troubleshooting
A detailed reference of over 100 kubectl commands covering cluster info, pod, service, deployment, networking, storage, security, scaling, and advanced debugging to help you quickly diagnose and resolve issues in Kubernetes environments.
This guide provides a curated collection of more than 100 kubectl commands useful for diagnosing and troubleshooting Kubernetes clusters. It is organized by diagnostic categories, each with concrete command examples and placeholders for namespace, pod, service, deployment, and other resource names.
Cluster Information
kubectl version– display client and server versions. kubectl cluster-info – show endpoint URLs for the control plane. kubectl get nodes – list all nodes. kubectl describe node <node-name> – detailed node information. kubectl get namespaces – list all namespaces. kubectl get pods --all-namespaces – list every pod across namespaces.
Pod Diagnosis
kubectl get pods -n <namespace> kubectl describe pod <pod-name> -n <namespace> kubectl logs <pod-name> -n <namespace> kubectl logs -f <pod-name> -n <namespace>(follow logs)
kubectl exec -it <pod-name> -n <namespace> -- <command>– run a command inside the pod.
Pod Health Checks
kubectl get pods <pod-name> -n <namespace> -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' kubectl get events -n <namespace> --field-selector involvedObject.name=<pod-name>Service Diagnosis
kubectl get svc -n <namespace> kubectl describe svc <service-name> -n <namespace>Deployment Diagnosis
kubectl get deployments -n <namespace> kubectl describe deployment <deployment-name> -n <namespace> kubectl rollout status deployment/<deployment-name> -n <namespace> kubectl rollout history deployment/<deployment-name> -n <namespace>StatefulSet Diagnosis
kubectl get statefulsets -n <namespace> kubectl describe statefulset <statefulset-name> -n <namespace>ConfigMap & Secret Diagnosis
kubectl get configmaps -n <namespace> kubectl describe configmap <configmap-name> -n <namespace> kubectl get secrets -n <namespace> kubectl describe secret <secret-name> -n <namespace>Namespace Diagnosis
kubectl describe namespace <namespace-name>Resource Usage
kubectl top pod <pod-name> -n <namespace> kubectl top nodesNetwork Diagnosis
kubectl get pods -n <namespace> -o custom-columns=POD:metadata.name,IP:status.podIP --no-headers kubectl get networkpolicies -n <namespace> kubectl describe networkpolicy <network-policy-name> -n <namespace>Persistent Volume & PVC Diagnosis
kubectl get pv kubectl describe pv <pv-name> kubectl get pvc -n <namespace> kubectl describe pvc <pvc-name> -n <namespace>Node Diagnosis
kubectl get pods --field-selector spec.nodeName=<node-name> -n <namespace> kubectl describe node <node-name> | grep Conditions -A5 kubectl describe node <node-name> | grep -E "Capacity|Allocatable"Resource Quotas & Limits
kubectl get resourcequotas -n <namespace> kubectl describe resourcequota <resource-quota-name> -n <namespace>Custom Resource Definition (CRD) Diagnosis
kubectl get <custom-resource-name> -n <namespace> kubectl describe <custom-resource-name> <custom-resource-instance-name> -n <namespace>Scaling & Autoscaling
kubectl scale deployment <deployment-name> --replicas=<replica-count> -n <namespace> kubectl autoscale deployment <deployment-name> --min=<min-pods> --max=<max-pods> --cpu-percent=<cpu-percent> -n <namespace> kubectl get hpa -n <namespace>Job & CronJob Diagnosis
kubectl get jobs -n <namespace> kubectl describe job <job-name> -n <namespace> kubectl get cronjobs -n <namespace> kubectl describe cronjob <cronjob-name> -n <namespace>Capacity Diagnosis
kubectl get pv --sort-by=.spec.capacity.storage kubectl get pv <pv-name> -o=jsonpath='{.spec.persistentVolumeReclaimPolicy}' kubectl get storageclassesIngress & Service Mesh Diagnosis
kubectl get ingress -n <namespace> kubectl describe ingress <ingress-name> -n <namespace> kubectl get virtualservices -n <namespace> kubectl describe virtualservice <virtualservice-name> -n <namespace>Pod Network Troubleshooting
kubectl run -it --rm --restart=Never --image=busybox net-debug-pod -- /bin/sh kubectl exec -it <pod-name> -n <namespace> -- curl <endpoint-url> kubectl exec -it <source-pod-name> -n <namespace> -- traceroute <destination-pod-ip> kubectl exec -it <pod-name> -n <namespace> -- nslookup <domain-name>Configuration Validation
kubectl apply --dry-run=client -f <yaml-file> kubectl auth can-i list pods --as=system:serviceaccount:<namespace>:<serviceaccount-name>RBAC & Security
kubectl get roles,rolebindings -n <namespace> kubectl describe role <role-name> -n <namespace>Service Account Diagnosis
kubectl get serviceaccounts -n <namespace> kubectl describe serviceaccount <serviceaccount-name> -n <namespace>Node Drain & Uncordon
kubectl drain <node-name> --ignore-daemonsets kubectl uncordon <node-name>Pod Disruption Budget (PDB) Diagnosis
kubectl get pdb -n <namespace> kubectl describe pdb <pdb-name> -n <namespace>Resource Locks (if used)
kubectl get resourcelocks -n <namespace>Endpoints & DNS
kubectl get endpoints <service-name> -n <namespace> kubectl exec -it <pod-name> -n <namespace> -- cat /etc/resolv.confCustom Metrics (Prometheus/Grafana)
Use kubectl port-forward to expose Prometheus/Grafana services and query custom metrics.
Pod Priority & Preemption
kubectl get priorityclassesPod Overhead (Kubernetes 1.18+)
kubectl get pod <pod-name> -n <namespace> -o=jsonpath='{.spec.overhead}'VolumeSnapshot Diagnosis (if used)
kubectl get volumesnapshot -n <namespace> kubectl describe volumesnapshot <snapshot-name> -n <namespace>Resource Deserialization
kubectl get <resource-type> <resource-name> -n <namespace> -o=jsonNode Taints
kubectl describe node <node-name> | grep TaintsWebhook Configurations
kubectl get mutatingwebhookconfigurations kubectl get validatingwebhookconfigurationsPod Network Policies
kubectl get networkpolicies -n <namespace>Node Conditions (Kubernetes 1.17+)
kubectl get nodes -o custom-columns=NODE:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status -l 'node-role.kubernetes.io/worker='Audit Logs
Check the cluster’s audit log configuration and location to retrieve audit events.
Node OS Details
kubectl get node <node-name> -o jsonpath='{.status.nodeInfo.osImage}'Replace placeholders such as <namespace>, <pod-name>, <deployment-name>, etc., with actual values from your environment before executing the commands.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
