Operations 7 min read

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.

Efficient Ops
Efficient Ops
Efficient Ops
6 Essential kubectl Tricks to Master Kubernetes Troubleshooting

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-namespaces

After 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.creationTimestamp

An alternative is kubectl describe on a specific object, which provides detailed information including node problems and resource limits.

kubectl describe deploy/figlet -n openfaas

3. 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=nginx

Tools 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 yaml

You 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=1

6. 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=LoadBalancer

Try these six commands on a real cluster to see how they simplify troubleshooting.

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.

cloud-nativeKubernetesDevOpstroubleshootingkubectl
Efficient Ops
Written by

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.

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.