Install/Upgrade scripts for K8S CLIs

Martien van den Akker
Nerd For Tech
Published in
2 min readJan 31, 2024

As you may know, I work with a Linux VM to do my daily work. In my previous article, I wrote about how I made it even more flexible.

I already had provisioners and scripts for kubectl and helm. They were already so “smart” that they tried to figure out what the latest versions were. And, dynamically build up the URL to download that version. Also, they checked if the tool wasn’t already available. If the tool is already there, then the download is skipped. But, they didn’t check if the currently installed version is the same as the latest. And, install the latest if they don’t match.

Today’s tasks suggest having the istioctl installed. So, I copied one of the scripts I already had and adapted that one to install the tool. You can find it in my Vagrant github project.

Being busy with that, I figured out how to check the current version of istioctl, and adapted the script to use that. If the versions don’t match, it will back up the current version of the tool using the current version. So, for instance, if you already have the file /usr/local/bin/istioctl, with version 1.20.0 it will be moved to: /usr/local/bin/istioctl-1.20.0. The second stage will then conclude that the tool is not installed and download and set up the latest version. The previous version is still available to restore if something is not working properly.

I adapted the install scripts for kubectl and helm to work in the same way as the one for istioctl.

When testing I found that my current Kubernetes environment is more than one version behind of the latest kubectl version. So, I added another script, installKubectlVersion.sh. It is an almost exact copy of installKubectl.sh. But, instead of getting the latest version, it gets the requested version from the first argument. You can call it as:

$ installKubectlVersion.sh v1.27.2

It will then compare the currently installed version with the requested version, and install the requested version if they don’t match.

Note that the output of the kubectl version is apparently changed after version v1.27.x. The current version of older versions will not be determined correctly. Also, the determination of the latest versions of the tools depend on how the projects publish the versions on their project sites. Changes on their setup may break the proper working of my scripts. When I stumble upon such an issue, I’ll try to fix that.

Happy kubectl-ing, helm-ing, or istioctl-ing!

--

--

Martien van den Akker
Nerd For Tech

Technology Architect at Oracle Netherlands. The views expressed on this blog are my own and do not necessarily reflect the views of Oracle