使用gcloud组件安装时如何设置kubectl的路径? [英] How to set path to kubectl when installed using gcloud components install?

查看:321
本文介绍了使用gcloud组件安装时如何设置kubectl的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在Mac上以以下方式安装了kubectl: 1)使用自制软件安装gcloud 2)使用gcloud组件安装程序安装了kubectl.

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

我想运行一个直接调用kubectl的shell脚本.但是,我得到一个错误. $ kubectl版本 -bash:kubectl:找不到命令

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

我希望安装gcloud组件来设置路径变量,以便可以调用kubectl.看起来还没有发生.我在Mac中搜索了kubectl,但找不到它.

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.

如何从命令行使用kubectl?

How can I get kubectl to work from command line?

推荐答案

简短答案:

在macOS上,您可能需要添加符号链接:sudo ln /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/kubectl /usr/local/bin/kubectl

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

详细答案:

我认为这是由于先通过Homebrew,然后通过gcloud安装kubectl,然后再卸载homebrew托管工具引起的. homebrew将删除其符号链接,但即使重新安装kubectl,gcloud也不会将其重新添加.

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.

要查看这是否在macOS上对您造成影响:

To see if this is affecting you on macOS:

  • 查看gcloud是否已安装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
    

  • 检查符号链接:ls -la /usr/local/bin | grep -i google-cloud-sdk.这将显示您到Google Cloud Binaries的链接.

    Check for the symlink: ls -la /usr/local/bin | grep -i google-cloud-sdk. That will show your links to google cloud binaries.

    • 如果kubectl不在列表中,请运行sudo ln /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/kubectl /usr/local/bin/kubectl
    • 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

    这篇关于使用gcloud组件安装时如何设置kubectl的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆