46

I want to upgrade the kubectl client version to 1.11.3.

I executed brew install kubernetes-cli but the version doesnt seem to be updating.

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.7", GitCommit:"0c38c362511b20a098d7cd855f1314dad92c2780", GitTreeState:"clean", BuildDate:"2018-08-20T10:09:03Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.4", GitCommit:"bf9a868e8ea3d3a8fa53cbb22f566771b3f8068b", GitTreeState:"clean", BuildDate:"2018-10-25T19:06:30Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}

I'm trying to get the logs for a cell by running this command.

kubectl logs -l groupname/cell=my-cell --all-containers=true

This works in my VM which has client version 1.11.3. But in my mac it gives me an error saying --all-containers=true flag is not available for kubectl logs command.

bfontaine
  • 18,169
  • 13
  • 73
  • 107
Madhuka Wickramapala
  • 1,344
  • 2
  • 14
  • 28

11 Answers11

63

Install specific version of kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/<specific-kubectl-version>/bin/darwin/amd64/kubectl

For your case if you want to install version v1.11.3 then replace specific-kubectl-version with v1.11.3

Then make this binary executable

chmod +x ./kubectl

Then move this binary to your PATH

sudo mv ./kubectl $(which kubectl)
Amal Thundiyil
  • 307
  • 1
  • 4
  • 9
Abu Hanifa
  • 2,857
  • 2
  • 22
  • 38
  • I already installed higher version. If I need to downgrade , then how i can do this ? – Mr.DevEng Jun 01 '19 at 13:14
  • use specific version to download. curl -LO https://storage.googleapis.com/kubernetes-release/release/``/bin/darwin/amd64/kubectl – Abu Hanifa Jun 01 '19 at 14:58
  • 2
    You can also use `curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl"` to automatically download the latest version – Mahdi May 08 '20 at 06:32
  • If using Linux, change the "darwin" bit of URL to "linux" – Francisco Cardoso Nov 03 '22 at 10:56
25

So, to upgrade kubectl on mac:

brew upgrade kubectl

Then you 'll probably need:

brew link --overwrite kubernetes-cli
DimiDak
  • 4,820
  • 2
  • 26
  • 32
  • 5
    if you have ran "brew upgrade kubectl" and get the msg "kubernetes-cli x.x.x is already installed" then, use "brew link --overwrite kubernetes-cli" to process oh, save my life~ – TomorJM Mar 10 '21 at 07:06
23

If you have installed it with brew, you can just run brew upgrade kubernetes-cli.

Milkncookiez
  • 6,817
  • 10
  • 57
  • 96
  • You may get warnings like "kubernetes-cli x.x.x is already installed, it's just not linked". Just follow the prompts for overwriting the link. The messages / warning are very helpful – Vijay Kumar Jan 07 '21 at 19:01
7

Step-1 - download latest or version-specific kubectl binary

Refer : https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/#install-kubectl-binary-with-curl-on-macos

Downloads$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   154  100   154    0     0    583      0 --:--:-- --:--:-- --:--:--   583
100 50.6M  100 50.6M    0     0  9159k      0  0:00:05  0:00:05 --:--:-- 10.8M

Step-2 : old version

➜  Downloads$ kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:13:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"darwin/amd64"}

Step-3 : old kubectl version location :

➜  Downloads$ which kubectl
/usr/local/bin/kubectl

Step-4 : move new version to the location :

➜  Downloads$ sudo mv kubectl /usr/local/bin/.
Password:

Step-5 : assign permission to kubectl binary

➜  Downloads$ kubectl version
zsh: permission denied: kubectl
➜  Downloads sudo chmod 755 /usr/local/bin/kubectl 

Step-6 : check new version

➜  Downloads$ kubectl version                      
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:45:37Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"darwin/amd64"}
Sumit Arora
  • 5,051
  • 7
  • 37
  • 57
5

I had installed kubectl using google-cloud-sdk. So in my path kubectl was pointing to this location. That is why the version did not update. Kubectl got updated after I removed that from the path.

Madhuka Wickramapala
  • 1,344
  • 2
  • 14
  • 28
3

To install OR upgrade the version of kubectl Server and Client on MacOS X is very easy if you follow the detailed install guide on the Kubernetes install page https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-macos

Hope it helps :)

3

Via Chocolatey:

choco upgrade kubernetes-cli
Rodion Sychev
  • 676
  • 9
  • 13
2

Similar to what boraas said. The version you are seeing is from another kubectl.exe installation. I had docker for windows installed which already has kubectl.exe (located in Docker\resources\bin) and was of older version. This gets used unless you provide explicitly the path to the new location of your kubectl.exe [you need to set it in PATH].

Shuma Dev
  • 33
  • 1
  • 5
  • This solved my issue. Why was kubectl used from the docker resources folder, when I had specified a path for the new kubectl executable? – JavaGeek Feb 13 '22 at 17:06
1

My docker desktop used an old version of kubectl. After installing gcloud components install kubectl the installer yields a warning of the location of the outdated kubectl version:

WARNING: There are older versions of Google Cloud Platform tools on your system PATH. Please remove the following to avoid accidentally invoking these old tools:

/Applications/Docker.app/Contents/Resources/bin/kubectl

I have removed the folder and kubectl run fine.

boraas
  • 929
  • 1
  • 10
  • 24
0

Thought this helps anybody in the same boat with aws kubectl.

I landed here after I faced problem while downloading kubectl from aws. kubectl installation was failing because I had kubectl in my machine.

After I removed, was able to install kubectl 1.15.11 from aws.

lrwxr-xr-x  1 root      admin      55 Jan 11 17:49 kubectl.docker -> /Applications/Docker.app/Contents/Resources/bin/kubectl
lrwxr-xr-x  1 root      admin      55 Jan 11 17:49 kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl 
user1769790
  • 1,183
  • 3
  • 11
  • 23
0

I'm using Windows and was stuck trying to update my 1.25 kubectl -> 1.27 (latest). I tried so many times to delete kubectl.exe file and double checking the path to my .exe was added to Path in system Env variables.

The kubectl.exe file that the machine recognized was actually in my Docker folder (Program Files-> Docker-> Docker-> resources-> bin).

If this is the same for you on PowerShell:

  1. Find where the file is:
where.exe kubectl
  1. Rename old kubectl version (to be safe)
Rename-Item "C:\Program Files\Docker\Docker\resources\bin\kubectl.exe" -NewName "C:\Program Files\Docker\Docker\resources\bin\kubectl-old.exe"
  1. Download new aws kubectl.exe in the same directory:
curl.exe -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.27.1/2023-04-19/bin/windows/amd64/kubectl.exe
  1. Check version
kubectl version --short --client

I really hope this works for those who were stuck like me. Good luck!

p_c
  • 93
  • 1
  • 5