Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kubectl multi-version brews

kubectl multi-version brews

We need to run multiple versions of kubectl for compatibility with various clusters.

It's a bit easier to get and use multiple versions of kubectl using Homebrew than it is using Macports.

With brew, it's simple to:

  • Install a bunch of versions of kubectl (in the kubernetes-cli Formula)
  • Switch between them as needed
  • Pin a particular release so you don't auto-upgrade into incompatibility

Preparation

Get the versions and commit IDs from

     https://github.com/Homebrew/homebrew-core/commits/master/Formula/kubernetes-cli.rb

or locally from your homebrew-core clone

     cd ~/src/github.com/Homebrew/homebrew-core

     git log master -- Formula/kubernetes-cli.rb

Then use the commit IDs to fetch a specific version via

    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/{commitIDhere}/Formula/kubernetes-cli.rb

(See Example Install Commands below)

Initial Installs

If you install a bunch of versions, they'll be available for hot brew switch action later.

Between each initial version install, you'll need to unlink each time to make way for the next version

     brew install ...

     brew unlink kubernetes-cli

     brew install ...

     brew unlink kubernetes-cli

     etc.

Once you have the versions installed, you don't need to unlink to switch between the versions.

Switching

To link up a specific version from your available versions

  • Check your active version

     kubectl version

  • Get available versions, short form, using the bogus version trick

     brew switch kubernetes-cli 0

  • Pick one version

     brew switch kubernetes-cli 1.8.5

  • Or pick another version

     brew switch kubernetes-cli 1.11.3

You could also get versions, long form with other info

     brew info kubernetes-cli

Pinning

Once you're switched to a version you want to stick with for a while, you can pin it to prevent upgrades during a global brew upgrade.

     brew pin kubernetes-cli

You'll need to brew unpin kubernetes-cli when you want to move back to the head release. Otherwise, you can switch between previously installed Formula versions while pinned.

Example Install Commands

Here are some versions' commit IDs all set up for you.

1.14.2

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/fa9f53755c04945496ee29d7d32cd1fcb00f3b3f/Formula/kubernetes-cli.rb

1.13.4

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/1827ebb2fe905c931deb283f7245eaf465c7cbbf/Formula/kubernetes-cli.rb

1.12.3

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/7a371a4d27fa6d80b1e37cac16c2dadcb78c7111/Formula/kubernetes-cli.rb

1.11.3

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/41764e07727d9a86b0f8a077117dc7876ca294c4/Formula/kubernetes-cli.rb

1.10.5

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d09d97241b17a5e02a25fc51fc56e2a5de74501c/Formula/kubernetes-cli.rb

1.9.6

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/505fcec7a3cf4f1a073b45bc7ae8294649a33f89/Formula/kubernetes-cli.rb

1.8.5

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e5538d7e7966795ae50cd94678ee7131fad2d7b7/Formula/kubernetes-cli.rb

1.7.6

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/1e866e9cd915c37184c248fb726775ff8a30c91e/Formula/kubernetes-cli.rb

1.6.6

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/4635c994b205a72c9e488b81306d46622fe72b1b/Formula/kubernetes-cli.rb

1.5.5

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/2d45e95b57c024eb9bda7c6fba9151a28bc0345f/Formula/kubernetes-cli.rb

@mlsaito

This comment has been minimized.

Copy link
Owner Author

commented Jun 10, 2019

Exactly what I'm looking for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.