6 Essential kubectl Tricks to Master Kubernetes Troubleshooting
This guide presents six practical kubectl commands—including get, events, logs, yaml output, scaling, and port‑forwarding—that help you quickly diagnose and resolve common deployment and pod issues in Kubernetes clusters.
After migrating from Docker to Docker Swarm and then Kubernetes, I’ve gathered the most useful kubectl troubleshooting techniques.
1. kubectl get deployment/pods
This command provides concise status information without overwhelming output; you should see ratios like 1/1 or 2/2 indicating successful deployment.
kubectl get deploy kubectl get deploy -n <namespace> kubectl get deploy --all-namespacesAfter confirming the deployment, you can inspect the pods with kubectl get pod to ensure the backing pods started correctly.
2. kubectl get events
Use this command to list events in a namespace, which is invaluable for spotting issues such as crashed pods or image‑pull failures.
kubectl get events --sort-by=.metadata.creationTimestampAn alternative is kubectl describe on a specific object, which provides detailed information including node problems and resource limits.
kubectl describe deploy/figlet -n openfaas3. kubectl logs
Retrieve logs from a deployment or pod; add -f to follow the stream. You can also filter by label.
kubectl logs deploy/cert-manager -n cert-manager kubectl logs deploy/cert-manager -n cert-manager -f kubectl logs -l app=nginxTools like stern or kail can help match patterns, though they may be distracting.
4. kubectl get -o yaml
When working with YAML generated by other projects or Helm, output the full manifest for inspection or editing.
kubectl run nginx-1 --image=nginx --port=80 --restart=Always kubectl get deploy/nginx-1 -o yamlYou can add --export to save the YAML locally, or use kubectl edit (set VISUAL=nano if you prefer a simpler editor).
5. kubectl scale
Scale a deployment down to zero replicas to stop all pods, then scale back up to recreate them.
kubectl scale deploy/nginx-1 --replicas=0 kubectl scale deploy/nginx-1 --replicas=16. Port forwarding
Expose a service or pod locally without exposing it to the Internet, useful for testing. kubectl port-forward deploy/nginx-1 8080:80 Port forwarding works with services as well, simulating production configurations. To expose a service externally, use a LoadBalancer or kubectl expose.
kubectl expose deployment nginx-1 --port=80 --type=LoadBalancerTry these six commands on a real cluster to see how they simplify troubleshooting.
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.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
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.
