Cloud Native 8 min read

6 Essential kubectl Tricks to Master Kubernetes Troubleshooting

Discover six practical kubectl commands—from inspecting deployments and events to streaming logs, editing YAML, scaling pods, and port-forwarding—that empower you to quickly diagnose and resolve common Kubernetes issues in real-world clusters effectively.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
6 Essential kubectl Tricks to Master Kubernetes Troubleshooting

After migrating from Docker to Docker Swarm and then to Kubernetes, and handling countless API changes over the years, I’m eager to discover deployment issues and fix them.

Today I’ll share what I consider the most useful troubleshooting tips and additional tricks for using kubectl as a Swiss‑army‑knife.

kubectl – The Swiss Army Knife

kubectl is our Swiss Army knife; we often use it when problems arise, and knowing how to use it is crucial. Let’s start with real‑world cases to see how to apply it during issues.

Scenario: My YAML is accepted, but the service fails to start or run properly.

1. kubectl get deployment/pods

This command shows concise, useful information without overwhelming output.

kubectl get deploy
kubectl get deploy -n <namespace>
kubectl get deploy --all-namespaces   # or -A

Ideally you see something like 1/1 or 2/2, indicating the deployment was accepted and attempted.

Next, you may check kubectl get pod to see if the backing pods started correctly.

2. kubectl get events

This command prints events in a given namespace, perfect for finding key problems such as crashed pods or image‑pull failures.

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

A related command is kubectl describe, which works with the object name, e.g.: kubectl describe deploy/figlet -n openfaas It provides detailed information, including node‑level issues that prevented pod startup.

3. kubectl logs

Many users misuse this command by first trying to locate the full pod name. You can log directly from a deployment:

kubectl logs deploy/cert-manager -n cert-manager

Add -f to follow the log stream:

kubectl logs deploy/cert-manager -n cert-manager -f

You can also filter by label, for example: 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, you often need to inspect it. For example, to run a quick test:

kubectl run nginx-1 --image=nginx --port=80 --restart=Always

Then retrieve its manifest: kubectl get deploy/nginx-1 -o yaml You can add --export to save the YAML locally for editing and re‑apply, or use kubectl edit (set VISUAL=nano if you’re uncomfortable with vim).

5. kubectl scale

The scale command can shrink a deployment to zero replicas, effectively killing all pods, and then scale back up to recreate them.

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

6. Port forwarding

Port‑forwarding lets you expose a service from your local or remote cluster on any configured port without exposing it to the Internet. kubectl port-forward deploy/nginx-1 8080:80 This works not only for deployments or pods but also for services, which better simulate production configurations.

If you need to expose a service externally, use a LoadBalancer service or run:

kubectl expose deployment nginx-1 --port=80 --type=LoadBalancer

Try these six commands and tricks on a real cluster; they should prove useful for diagnosing and fixing issues.

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.

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