Kubernetes is managed and used by utilizing the command line interface kubectl
. I got a ton of questions regarding my terminal configuration for daily k8s tasks. Questions like โWhich aliases do you use for regular k8s tasks?โ or โHow did you get autocompletion for all the k8s stuff up and running on your mac?โ
So this post will answer those questions quickly to ensure everyone will become more productive and can spin up even more pods and nodes in less time ๐
Create an kubectl alias
kubectl
is an amazing CLI. There is only one disadvantage, the name. I can’t recall how many times my terminal was saying
zsh: command not found: kuberclt
# or
zsh: command not found: kubctl
Or referring to any of the other 1000 typos. Thankfully each and every shell can deal with aliases. No matter if you use bash or oh-my-zsh, the configuration syntax for aliases is dead simple and consistent across most important shells. Simply add the following line to your .zshrc
or .bashrc
file.
alias k="kubectl"
Restart the terminal or source the config file source ~/.zshrc
and you’re done. You can access kubectl
by simply hitting k
.
Enable autocompletion for kubectl
Enabling autocompletion for kubectl
heavily depends on the shell you’re using. To be honest, I don’t know if each shell is able to provide autocompletion for kubectl
. That’s the point when oh-my-zsh enters the stage. That shell is awesome, easy to configure and it has a minimal time-to-code.
time-to-code is a term that describes the time you spent from unboxing your shiny new notebook till writing the first line of code or executing the first command in this case. (hopefully, neither Andrew Connell nor Chris Johnson have a trademark for that term).
Once you’ve installed oh-my-zsh๐, you can easily enable the kubectl plugin by adding kubectl
to the list of plugins in your .zshrc
. That should look similar to this:
# somewhere in your zshrc
plugins=(git git-flow brew history node npm kubectl)
That’s it. Nothing more is required. oh-my-zsh does all the magic for you. Autocompletion will work for both: kubectl
and the recently created alias k
.
Having this configuration in place, you’ll gain more speed when working with Kubernetes and you’ll produce less typos!