Miguel David |||

Using multiple versions of kubectl on macOS

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?

  1. Uninstall any kubectl that you have installed
  2. Install asdf using brew: brew install asdf
  3. Export the shims to your path: export PATH=$PATH:$HOME/.asdf/shims in .bash_profile/.bashrc
  4. Install the plugin: asdf plugin-add kubectl
  5. Install whichever versions you need. For example: asdf install kubectl 1.13.4 or asdf install kubectl 1.15.0
  6. Set the default system version to one of them: asdf global kubectl 1.13.4
  7. Check kubectl’s active version: kubectl version
  8. Now go to a folder of a project that uses a different version of kubectl and set the local version to that: asdf local kubectl 1.15.0
  9. Check locally: kubectl version
  10. You’re done!

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!

Up next Merging two MySQL (or MySQL compatible) databases in AWS using DMS Most projects don’t start out knowing exactly how their infrastructure will turn out. That is one of the reasons I like infrastructure-as-code, but My git flow I have yet to meet an engineer who does not like to optimise. We like solving puzzles, work with constraints and make science apply to real life.
Latest posts Git: Choose Your Adventure Stop before you’re stopped Today I learned about git and permissions Today I learned about view My git flow Using multiple versions of kubectl on macOS Merging two MySQL (or MySQL compatible) databases in AWS using DMS Inspired Recommendations for Portugal God is dead (and we are suffering from it) Advice to my unborn child: be a plumber and an artist On light and shadow You can usually do more/better than you think you can Upkeep Comparing myself to others Fear, Procrastination. Procrastination, Fear Liberalism and a new system Chores Finding my calm place Turning 38 Privilege Humbling Habits Frustration The miracle of the blank page On being late Love is the base of it all A letter to my dead grandfather Self imposed stress Rent the world Start at 6:30