The Ultimate kubectl Cheat Sheet from Beginner to Kubernetes Ninja!
Why 90% of Kubernetes engineers are using kubectl wrong (and how to fix it)
Hey there, fellow Kubernetes warriors! If you're reading this, chances are you've either just started your Kubernetes journey and kubectl feels overwhelming. However, you may have been using kubectl for months but suspect you're missing some magic, or you consider yourself experienced but want to level up your game. Here's the truth: Most engineers use maybe 10% of kubectl's true power.
After working with Kubernetes for years and training hundreds of engineers, I've noticed the same patterns over and over. People know kubectl get pods
and kubectl apply -f
, but they're missing the commands that separate the pros from the beginners. Today, I'm sharing the game-changing kubectl techniques that will transform how you work with Kubernetes.
The kubectl reality check
Before we dive in, let's do a quick reality check. Can you answer these questions without looking them up?
How do you find all pods consuming more than 100MB of memory?
What's the fastest way to debug a service that's not accessible?
How do you safely drain a node without causing downtime?
What's the difference between
kubectl patch
strategies?
If you hesitated on any of these, you're not alone. These are the gaps that separate good engineers from great ones.
kubectl commands that matter
Let's start with the commands you'll use 80% of the time (but probably don't know all their options). For instance when it comes to switching contexts:
# Instead of this amateur move:
kubectl config use-context production-cluster
# Do this:
kubectl config current-context
kubectl config get-contexts | grep prod
Most engineers waste 5-10 minutes daily switching contexts. Here's the pro move: always know where you are before you act.
Resource Inspection
# Beginner level:
kubectl get pods
# Professional level:
kubectl get pods -o wide --show-labels --sort-by=.metadata.creationTimestamp
That single command gives you:
Node placement
All labels (crucial for debugging)
Creation timeline
This is diagnostic gold that most engineers never use.
JSONPath Secret is a game changer
Here's where things get interesting. While everyone else is scrolling through YAML output, pros use JSONPath to extract exactly what they need:
# Find all pods with their IP addresses
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}'
# Get container images across all pods
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
This changes everything. Instead of manual parsing, you get structured data instantly.
Network debugging
# Most people do this:
kubectl logs <pod-name>
# Smart engineers do this:
kubectl run -it --rm debug --image=nicolaka/netshoot --restart=Never -- /bin/bash
That netshoot
image contains every network debugging tool you'll ever need. It's like having a Swiss Army knife for network issues.
Event timeline
kubectl get events --sort-by=.metadata.creationTimestamp --field-selector involvedObject.name=<pod-name>
This shows you the exact timeline of what happened to your pod. It's like having a black box recorder for your Kubernetes resources.
Performance optimization
Here's something that will blow your mind. Most kubectl performance issues come from inefficient queries, not cluster problems.
# Slow (queries everything):
kubectl get pods | grep nginx
# Fast (server-side filtering):
kubectl get pods -l app=nginx
The difference? The first command transfers all pod data to your client, then filters. The second filters on the server. With large clusters, this can mean the difference between 10 seconds and 100 milliseconds.
Emergency commands
When things go wrong (and they will), these commands separate the heroes from the zeros:
Force delete:
kubectl delete pod <pod-name> --force --grace-period=0
Drain a node
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data
Instant deployment restart
kubectl rollout restart deployment/<deployment-name>
These aren't just commands; they're career-saving techniques for when you're in the hot seat during an incident.
Automation
Here's what separates senior engineers from junior ones: automation thinking. Instead of running commands manually, they create reusable patterns:
# Create a function for quick namespace switching
kns() {
kubectl config set-context --current --namespace=$1
}
# Quick pod inspection
kpod() {
kubectl get pods -o wide --show-labels | grep $1
}
Security patterns that are good to know
Security in Kubernetes starts with kubectl. Here are the commands that matter:
# Check your permissions
kubectl auth can-i create pods
kubectl auth can-i create pods --as=<user>
# Audit security contexts
kubectl get pods <pod-name> -o jsonpath='{.spec.securityContext}'
In today's security-conscious world, these aren't nice-to-haves—they're essential skills.
Download the ultimate cheat sheet
If you found this valuable, imagine what you could do with the complete kubectl mastery system.
Check out the Ultimate kubectl Cheat Sheet. This is a comprehensive reference that covers every technique I've learned in years of Kubernetes operations. It includes:
✅ 200+ commands with real-world examples
✅ Troubleshooting playbooks for common scenarios
✅ Performance optimization techniques
✅ Security patterns and best practices
✅ Emergency response procedures
✅ Automation templates you can use immediately
It is a tool that will make you more efficient, more confident, and more valuable as a Kubernetes engineer.
👇 Download it below for paid members:
Keep reading with a 7-day free trial
Subscribe to Between the Clouds Newsletter to keep reading this post and get 7 days of free access to the full post archives.