kubectl is your window into the Kubernetes cluster. Everyone knows the basic commands, but there are tricks that dramatically boost productivity. Here are our favorites.
Aliases — Because kubectl get pods Is Too Long¶
alias k=kubectl
alias kgp='kubectl get pods'
alias kgs='kubectl get services'
alias kgd='kubectl get deployments'
alias kl='kubectl logs'
alias ke='kubectl exec -it'
alias kd='kubectl describe'
alias kaf='kubectl apply -f'
Contexts and Namespaces¶
kubectx and kubens are must-have tools. Quick switching between clusters and namespaces. You’ll avoid accidentally deploying to production when you meant staging.
JSONPath and Custom Columns¶
# Just pod names and their nodes
kubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName
# Pods with restarts > 0
kubectl get pods -o json | jq '.items[] | select(.status.containerStatuses[].restartCount > 0) | .metadata.name'
Debug Commands¶
kubectl top pods— resource usagekubectl get events --sort-by=.lastTimestamp— what’s happeningkubectl port-forward svc/myservice 8080:80— direct accesskubectl run debug --image=busybox -it --rm -- sh— debug podkubectl auth can-i create deployments— RBAC check
kubectl Plugins (krew)¶
krew is a package manager for kubectl plugins. Recommended: kubectl-tree (resource hierarchy), kubectl-neat (clean YAML output), kubectl-sniff (packet capture from a pod).
Investing in kubectl Productivity Pays Off¶
10 minutes setting up aliases and plugins will save you hours per week. kubectl is powerful — learn to use it to its full potential.
Need help with implementation?
Our experts can help with design, implementation, and operations. From architecture to production.
Contact us