Managing Multiple Kubectl Versions | Shorts

Vishnu Deva
2 min readAug 6, 2022

--

Kubernetes versions move fast, and we might find ourselves managing clusters that are 4 or 5 minor versions apart. And since upgrading K8s is not a trivial task, we’ll always be playing catch-up with some clusters.

Right now, for example, I have to use a 1.18 cluster and a 1.22 cluster simultaneously, which is painful because the version of kubectl you use to access a cluster can only be a maximum of one minor version away: skew ≤ 1. But in my case, the skew = 4, which means that I need a different kubectl binary for each cluster.

Managing these binaries directly is out of the question, it’s just not a clean solution. Instead, we use the ‘asdf’ tool version manager.

  • Install asdf.
  • Install the asdf kubectl plugin.
  • Before accessing a specific cluster, we request asdf for the correct kubectl version to be enabled.
  • That’s it!

Steps

Core Installation

Taken from here.

# Clone the asdf Github Repository to ~/.asdf
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
# Add the following lines to ~/.bashrc if on Linux.
# Or to ~/.bash_profile if on MacOS.
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

Kubectl Plugin Installation

Taken from here.

# Install the kubectl plugin.
asdf plugin-add kubectl
# Install specific versions of kubectl as needed.
asdf install kubectl 1.18.20
asdf install kubectl 1.22.10

Use asdf

# To enable 1.18 access, run:
asdf global kubectl 1.18.20
# To enable 1.22 access, run:
asdf global kubectl 1.22.10

In cases where a single machine is shared by multiple people, use local instead of global to use multiple versions of kubectl simultaneously.

asdf local kubectl 1.18.20
asdf local kubectl 1.22.10

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response