How to set path to kubectl when installed using gcloud components install?

青春壹個敷衍的年華 提交于 2020-01-04 04:12:11

问题


Ok, I installed kubectl in the following way on my Mac: 1) installed gcloud using homebrew 2) installed kubectl using gcloud components install.

I want to run a shell script that calls kubectl directly. However, I get an error. $ kubectl version -bash: kubectl: command not found

I expected gcloud components install to set path variables so that I can call kubectl. Looks like that has not happened. I searched for kubectl in my mac but was not able to find it.

How can I get kubectl to work from command line?


回答1:


The gcloud info command will tell you if and where kubectl is installed.

Per https://kubernetes.io/docs/tasks/tools/install-kubectl/, you can install kubectl with brew install kubernetes-cli. Alternatively, you can install the Google Cloud SDK per https://cloud.google.com/sdk/docs/quickstart-macos, and then install kubectl with gcloud components install kubectl.




回答2:


Short answer:

On macOS, you may need to add a symlink: sudo ln /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/kubectl /usr/local/bin/kubectl

Long answer:

I believe this is caused by installing kubectl via homebrew, then via gcloud, and then uninstalling the homebrew managed tool. homebrew will remove its symlink but gcloud doesn't add it back even when you reinstall kubectl.

To see if this is affecting you on macOS:

  • See if gcloud has installed kubectl: gcloud info | grep -i kubectl

    • If you are having the problem I am, I'd expect to see the output look something like this:
        kubectl: [2019.05.31]
      Kubectl on PATH: [False]
      
    • When working you should see something like this:
        kubectl: [2019.05.31]
      Kubectl on PATH: [/usr/local/bin/kubectl]
        /usr/local/bin/kubectl
      
  • Check for the symlink: ls -la /usr/local/bin | grep -i google-cloud-sdk. That will show your links to google cloud binaries.

    • If kubectl isn't on the list then run sudo ln /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/kubectl /usr/local/bin/kubectl


来源:https://stackoverflow.com/questions/51429553/how-to-set-path-to-kubectl-when-installed-using-gcloud-components-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!