34

I started minikube with k8s version 1.5.2 and I would like to downgrade my kubectl so that it is also 1.5.2. Currently when I run kubectl version I get:

Client Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.5", GitCommit:"17d7182a7ccbb167074be7a87f0a68bd00d58d97", GitTreeState:"clean", BuildDate:"2017-08-31T19:32:12Z", GoVersion:"go1.9", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"1970-01-01T00:00:00Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64"}

I would like to use kubectl to fetch PetSets but in later versions this was updated to StatefulSets so I cannot use the commands with my current kubectl version

kubectl get petsets
the server doesn't have a resource type "petsets"

Thanks!

appdap1
  • 521
  • 1
  • 6
  • 17

5 Answers5

69

You can just download the previous version binary and replace the one you have now.

Linux:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.5.2/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

macOS:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.5.2/bin/darwin/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Windows:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.5.2/bin/windows/amd64/kubectl.exe

And add it to PATH.

If not follow instructions for other Operating Systems here: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl

vascop
  • 4,972
  • 4
  • 37
  • 50
  • I'm on MAC. When I followed the instructions on the site. After completing them and running `kubectl version` I get the following message: `-bash: /usr/local/bin/kubectl: cannot execute binary file` – appdap1 Oct 06 '17 at 16:44
  • I fixed the issue looks like I was downloading for linux instead of mac. Thanks! – appdap1 Oct 06 '17 at 16:58
  • 2
    Saving you mac users the extra 30 seconds `curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.11.0/bin/darwin/amd64/kubectl` Update your version as needed. – Skam Aug 31 '18 at 20:14
  • @Skam: I don't think this would replace the current version which OP was asking originally. – RVM Nov 22 '18 at 11:59
  • My advice to all is, use the url provided in the k8s official doc (at this point in time is "https://dl.k8s.io") and follow the official doc hardcoding the version you want. Always be safe out there. ;) – lao Jan 26 '22 at 10:13
5

With APT you can install the exact version as well:

sudo apt install kubectl=1.17.2-00
Vladas Diržys
  • 1,358
  • 1
  • 11
  • 9
2

In my macOS, I was struggling, because I had multiple kubectl executables installed. First you need to remove the existing kubectl binaries. Do the following iteratively until it says command not found: kubectl.

which kubectl
sudo rm -f <path-from-above-command>

Next, follow the kubernetes official documentation to install your specific kubectl version. https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/

  1. If you want to install v1.18.0 for Apple M1 (see the above link for other OS versions)

curl -LO "https://dl.k8s.io/release/v1.18.0/bin/darwin/arm64/kubectl"

  1. Make the kubectl binary executable.

chmod +x ./kubectl

  1. Move the kubectl binary to a file location on your system PATH.

sudo mv ./kubectl /usr/local/bin/kubectl

sudo chown root: /usr/local/bin/kubectl

  1. Test to ensure the version you installed is up-to-date:

kubectl version --client

Keet Sugathadasa
  • 11,595
  • 6
  • 65
  • 80
1

What helped me on Centos was running the following:

sudo yum downgrade kubeadm-1.16.9 kubernetes-cni-0.7.5 kubelet-1.16.9 kubectl-1.16.9

Then to disable updates forever, edit /etc/yum.repos.d/Kubernetes.repo and change the line with enabled to enabled=0.

james-see
  • 12,210
  • 6
  • 40
  • 47