When you work with multiple clients, or maybe with one company that has clusters in different versions of Kubernetes, you need to have a kubectl
(Kubernetes client) binary on your Mac that is not necessarily the only that brew
package manager offers (which is usually the latest). Kubernetes has a lee way of one version back and forth between the kubernetes server side and the kubernetes client side, but the 3 month release cycle is quite aggressive for stable companies. So how can you keep multiple versions of kubectl and switch to the one you need on demand? Enter asdf
. asdf
is like nvm
, or pyenv
, or rbenv
, it’s a version manager. Unlike the others though, it is extendable which is why there is a kubectl plugin.
How to get it working?
asdf
using brew
: brew install asdf
export PATH=$PATH:$HOME/.asdf/shims
in .bash_profile
/.bashrc
asdf plugin-add kubectl
asdf install kubectl 1.13.4
or asdf install kubectl 1.15.0
asdf global kubectl 1.13.4
kubectl version
asdf local kubectl 1.15.0
kubectl version
The way it does it is with a file called .tool-versions
in the relevant path.
~ $ cat .tool-versions
kubectl 1.15.0
Which means that you can also use asdf
to control the versions of other tools simultaneously, like ruby for example!
Want to play around more? Here is the commands list
I hope this helps!