Operations 6 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—along with detailed usage tips to help you quickly diagnose and resolve common issues in Kubernetes deployments.

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

1. kubectl get deployment/pods

This command provides concise status information without overwhelming output; you typically want to see a replica count like 1/1 indicating the deployment was accepted and is being rolled out.

kubectl get deploy
kubectl get deploy -n <namespace>
kubectl get deploy -A

After confirming the deployment, you can inspect the backing pods with kubectl get pod.

2. kubectl get events

Use this command to list events in a namespace, which is invaluable for spotting problems such as crashed pods or image‑pull failures. Sorting by creation timestamp makes the timeline clear.

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

For even more detail, kubectl describe works like get but provides a full description of the selected object.

kubectl describe deploy/figlet -n openfaas

3. kubectl logs

Many users misuse this command by trying to fetch logs with a pod’s full name. Instead, you can log directly from a deployment or use label selectors.

kubectl logs deploy/cert-manager -n cert-manager
kubectl logs deploy/cert-manager -n cert-manager -f
kubectl logs -l app=nginx

Adding -f follows the log stream in real time.

4. kubectl get -o yaml

When working with YAML generated by other tools (e.g., Helm), you often need to view or edit it. You can export the manifest for local editing or use the built‑in editor.

kubectl run nginx-1 --image=nginx --port=80 --restart=Always
kubectl get deploy/nginx-1 -o yaml
kubectl edit deploy/nginx-1   # set VISUAL=nano if vim is unfamiliar

5. kubectl scale

Scaling a deployment to zero replicas effectively stops all pods; scaling back to one creates a fresh pod and restarts the application.

kubectl scale deploy/nginx-1 --replicas=0
kubectl scale deploy/nginx-1 --replicas=1

6. Port forwarding

Port‑forwarding lets you expose a service locally without making it publicly reachable. It works with deployments, pods, or services, and is useful for testing.

kubectl port-forward deploy/nginx-1 8080:80
kubectl expose deployment nginx-1 --port=80 --type=LoadBalancer

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

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.

OperationsKubernetesDevOpstroubleshootingkubectl
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.