Cloud Native 17 min read

Master 100 Essential kubectl Commands for Rapid Kubernetes Troubleshooting

This guide compiles 100 practical kubectl commands covering cluster information, pod, service, deployment, storage, networking, security, scaling, and more, enabling you to diagnose and resolve Kubernetes issues quickly and confidently.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master 100 Essential kubectl Commands for Rapid Kubernetes Troubleshooting

Introduction

This article provides a comprehensive list of 100 commonly used kubectl commands for diagnosing Kubernetes clusters, helping you troubleshoot issues efficiently.

Cluster Information

kubectl version

– Show Kubernetes version. kubectl cluster-info – Display cluster information. kubectl get nodes – List all nodes. kubectl describe node <node-name> – Show details of a specific node. kubectl get namespaces – List all namespaces. kubectl get pods --all-namespaces – List all pods across namespaces.

Pod Diagnosis

kubectl get pods -n <namespace>

– List pods in a namespace. kubectl describe pod <pod-name> -n <namespace> – Show pod details. kubectl logs <pod-name> -n <namespace> – View pod logs. kubectl logs -f <pod-name> -n <namespace> – Follow pod logs.

kubectl exec -it <pod-name> -n <namespace> -- <command>

– Execute a command inside a pod.

Pod Health Checks

kubectl get pods <pod-name> -n <namespace> -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'

– Check pod readiness.

kubectl get events -n <namespace> --field-selector involvedObject.name=<pod-name>

– View pod events.

Service Diagnosis

kubectl get svc -n <namespace>

– List services.

kubectl describe svc <service-name> -n <namespace>

– Show service details.

Deployment Diagnosis

kubectl get deployments -n <namespace>

– List deployments.

kubectl describe deployment <deployment-name> -n <namespace>

– Show deployment details.

kubectl rollout status deployment/<deployment-name> -n <namespace>

– Check rollout status.

kubectl rollout history deployment/<deployment-name> -n <namespace>

– View rollout history.

StatefulSet Diagnosis

kubectl get statefulsets -n <namespace>

– List StatefulSets.

kubectl describe statefulset <statefulset-name> -n <namespace>

– Show details.

ConfigMap and Secret Diagnosis

kubectl get configmaps -n <namespace>

– List ConfigMaps.

kubectl describe configmap <configmap-name> -n <namespace>

– Show ConfigMap details. kubectl get secrets -n <namespace> – List Secrets.

kubectl describe secret <secret-name> -n <namespace>

– Show Secret details.

Namespace Diagnosis

kubectl describe namespace <namespace-name>

– Show namespace details.

Resource Usage

kubectl top pod <pod-name> -n <namespace>

– Check pod CPU/memory. kubectl top nodes – Check node resource usage.

Network Diagnosis

kubectl get pods -n <namespace> -o custom-columns=POD:metadata.name,IP:status.podIP --no-headers

– Show pod IPs. kubectl get networkpolicies -n <namespace> – List network policies.

kubectl describe networkpolicy <network-policy-name> -n <namespace>

– Show policy details.

Persistent Volume (PV) and Persistent Volume Claim (PVC) Diagnosis

kubectl get pv

– List PVs. kubectl describe pv <pv-name> – Show PV details. kubectl get pvc -n <namespace> – List PVCs. kubectl describe pvc <pvc-name> -n <namespace> – Show PVC details.

Node Diagnosis

kubectl get pods --field-selector spec.nodeName=<node-name> -n <namespace>

– List pods on a node.

Resource Quotas and Limits

kubectl get resourcequotas -n <namespace>

– List resource quotas.

kubectl describe resourcequota <resource-quota-name> -n <namespace>

– Show quota details.

Custom Resource Definition (CRD) Diagnosis

kubectl get <custom-resource-name> -n <namespace>

– List custom resources.

kubectl describe <custom-resource-name> <custom-resource-instance-name> -n <namespace>

– Show details.

Scaling and Autoscaling

kubectl scale deployment <deployment-name> --replicas=<replica-count> -n <namespace>

– Scale a deployment.

kubectl autoscale deployment <deployment-name> --min=<min-pods> --max=<max-pods> --cpu-percent=<cpu-percent> -n <namespace>

– Set autoscaling. kubectl get hpa -n <namespace> – Check Horizontal Pod Autoscaler status.

Job and CronJob Diagnosis

kubectl get jobs -n <namespace>

– List jobs. kubectl describe job <job-name> -n <namespace> – Show job details. kubectl get cronjobs -n <namespace> – List CronJobs.

kubectl describe cronjob <cronjob-name> -n <namespace>

– Show CronJob details.

Capacity Diagnosis

kubectl get pv --sort-by=.spec.capacity.storage

– List PVs sorted by capacity.

kubectl get pv <pv-name> -o=jsonpath='{.spec.persistentVolumeReclaimPolicy}'

– Show PV reclaim policy. kubectl get storageclasses – List storage classes.

Ingress and Service Mesh Diagnosis

kubectl get ingress -n <namespace>

– List Ingresses.

kubectl describe ingress <ingress-name> -n <namespace>

– Show Ingress details. kubectl get virtualservices -n <namespace> – List Istio VirtualServices.

kubectl describe virtualservice <virtualservice-name> -n <namespace>

– Show VirtualService details.

Pod Network Troubleshooting

kubectl run -it --rm --restart=Never --image=busybox net-debug-pod -- /bin/sh

– Launch a debugging pod.

kubectl exec -it <pod-name> -n <namespace> -- curl <endpoint-url>

– Test connectivity.

kubectl exec -it <source-pod-name> -n <namespace> -- traceroute <destination-pod-ip>

– Trace network path.

kubectl exec -it <pod-name> -n <namespace> -- nslookup <domain-name>

– Check DNS resolution.

Configuration and Resource Validation

kubectl apply --dry-run=client -f <yaml-file>

– Validate YAML without applying.

kubectl auth can-i list pods --as=system:serviceaccount:<namespace>:<serviceaccount-name>

– Verify pod security context.

RBAC and Security

kubectl get roles,rolebindings -n <namespace>

– List roles and bindings. kubectl describe role <role-name> -n <namespace> – Show role details.

Service Account Diagnosis

kubectl get serviceaccounts -n <namespace>

– List service accounts.

kubectl describe serviceaccount <serviceaccount-name> -n <namespace>

– Show account details.

Node Drain and Uncordon

kubectl drain <node-name> --ignore-daemonsets

– Drain a node for maintenance. kubectl uncordon <node-name> – Uncordon a node.

Resource Cleanup

kubectl delete pod <pod-name> -n <namespace> --grace-period=0 --force

– Force delete a pod (use with caution).

Pod Affinity and Anti‑Affinity

kubectl get pod <pod-name> -n <namespace> -o=jsonpath='{.spec.affinity}'

– Show pod affinity rules.

kubectl get pod <pod-name> -n <namespace> -o=jsonpath='{.spec.affinity.podAntiAffinity}'

– Show anti‑affinity rules.

Pod Security Policy (PSP)

kubectl get psp

– List all PSPs.

Events

kubectl get events --sort-by=.metadata.creationTimestamp

– List recent cluster events. kubectl get events -n <namespace> – Filter events by 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='

– Custom node readiness output.

Audit Logs

Retrieve audit logs if enabled to understand cluster activity.

Node OS Details

kubectl get node <node-name> -o jsonpath='{.status.nodeInfo.osImage}'

– Get node operating system image.

Replace placeholders such as <namespace>, <pod-name>, <service-name>, <deployment-name>, etc., with actual values from your cluster.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KubernetesdiagnosticscommandskubectlCluster Troubleshooting
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.