I run probably more than a hundred
kubectl commands on some days, as you can
tell I like to try out things. After a while I started to notice some
and realized I can pretty much condense 99% of all my
kubectl usage into
single-word bash aliases.
This looks probably really stupid, yet it’s SUPER USEFUL to me! I actually save a lot of time in my everyday workflow. The syntax is basically:
To give a concrete example, a small alias like:
or a more complex one:
Every operation, resource, option/arg has a shorthand notation. At the end you just merge all the shorthands and get an alias. It’s HARD to wrap your mind around it at first, but once you get used to it, I think it works perfectly (therefore I’m open sourcing and taking time to explain it).
Some example aliases that make up
kubectl get operation for pods:
alias k='kubectl' alias kg='kubectl get' alias kgpo='kubectl get pods' alias kgpoojson='kubectl get pods -o=json' alias kgpon='kubectl get pods --namespace' alias ksysgpooyamll='kubectl --namespace=kube-system get pods -o=yaml -l'
Similarly tons of aliases for
alias krm='kubectl delete' alias krmf='kubectl delete -f' alias krming='kubectl delete ingress' alias krmingl='kubectl delete ingress -l' alias krmingall='kubectl delete ingress --all-namespaces'
And there are some useful non-operation aliases, too:
alias ka='kubectl apply -f' alias klo='kubectl logs -f' alias kex='kubectl exec -i -t'
kubectl tab completions
still work fine with these aliases, so you’re not losing that speed.
I actually use all these stuff on a daily basis, so I hope it does not seem too ridiculous to you. I get that this is super hardcore and does not seem ideal. If you are just getting started with Kubernetes, check out kube-shell , which provides an interactive shell with neat inline explanation and completion capabilities of all arguments.
If you have ideas for new aliases, experimenting with it is super easy. Here is the source code if you are interested.