Introduction

If you work with Kubernetes, chances are you use kubectl every day. It’s the Swiss Army knife of Kubernetes — powerful, flexible, and sometimes… a bit tedious.

But what if you could speed things up, save keystrokes, and even have a little fun along the way?

In this guide, I’ll share some handy kubectl tricks that I use regularly to make working with Kubernetes faster and smoother. Whether you’re just getting started or already knee-deep in clusters, you’ll likely find something useful here.

1. Switch Between Clusters Like a Pro

Managing multiple clusters? Switching contexts manually can get annoying:

kubectl config use-context my-cluster
kubectl config get-contexts

Use kubectx for even faster context switching.

2. View Resources with Custom Columns

Sometimes, the default output from kubectl is overkill. You can get exactly what you need with custom columns:

kubectl get pods -o custom-columns="NAME:.metadata.name,STATUS:.status.phase"

3. Watch Resource Changes in Real-Time

Want to keep an eye on your resources as they change?

kubectl get pods --watch

4. Jump into a Pod Shell

Need to poke around inside a container?

kubectl exec -it my-pod -- /bin/sh

5. Apply YAML from stdin

Sometimes you want to test something quickly:

cat pod.yaml | kubectl apply -f -

6. Port Forward a Pod to Localhost

Need to hit a service from your local machine?

kubectl port-forward svc/my-service 8080:80

7. Set a Temporary Alias

Tired of typing kubectl all the time? Me too.

alias k='kubectl'

8. Output as YAML/JSON

Perfect for scripting or debugging:

kubectl get pod mypod -o yaml
kubectl get pod mypod -o json

Final Thoughts

Working efficiently with kubectl isn’t just about saving time — it’s about staying in flow, reducing friction, and understanding your cluster more deeply.

These tricks are part of my daily workflow, and they’ve saved me countless hours. Hopefully, they’ll do the same for you.

Got a favorite kubectl trick I missed? Let me know — I’m always looking to level up my toolkit

Want to take your Kubernetes workflow further? Check out my guide to Helm basics — a powerful tool for managing applications declaratively.