有旧版本的 Google 云平台工具:Docker

There are older versions of Google Cloud Platform tools: Docker

更新 gcloud 后我收到此警告,但我该怎么做(我应该删除 Docker)吗?

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

我的 .zshrc 中有这个:

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/<NAME>/google-cloud-sdk/path.zsh.inc' ]; then source '/Users/<NAME>/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/Users/<NAME>/google-cloud-sdk/completion.zsh.inc' ]; then source '/Users/<NAME>/google-cloud-sdk/completion.zsh.inc'; fi

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

发生这种情况是因为 docker-for-mac 为 kubectl 安装了一个 bin,而 gcloud-sdk 也安装了另一个带有 gcloud components install kubectl.

的 bin

我的建议是从 gcloud 中卸载 kubectl 作为组件,覆盖来自 docker-for-mac 的符号链接,并且只使用自制程序安装的 bin。

试试这个命令:

gcloud components remove kubectl

brew install kubernetes-cli

brew link --overwrite kubernetes-cli

这是我的案例,您可以参考。在 运行 gcloud components update 之后,我收到了这个警告:

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:

/usr/local/Cellar/kubernetes-cli/1.10.2/bin/kubectl

我使用 brew list

检查此工具
☁  issue [master] brew list
coreutils       gdbm            git-lfs         icu4c           kops            kubectx         libpng          mtr             openssl         python@2        sqlite          tree            wxmac
erlang          geoip           git-redate      jpeg            kube-ps1        kubernetes-cli  libtiff         node            pcre            readline        telnet          watchman

看完doc。我决定卸载 kubernetes-cli 及其依赖项 kopskube-ps1kubectx 以避免冲突。

☁  issue [master] brew uninstall kops kube-ps1 kubectx
Uninstalling /usr/local/Cellar/kops/1.9.0... (5 files, 129.8MB)
Uninstalling /usr/local/Cellar/kube-ps1/0.6.0... (6 files, 29.0KB)
Uninstalling /usr/local/Cellar/kubectx/0.5.0... (12 files, 27.8KB)
☁  issue [master] brew uninstall kubernetes-cli
Uninstalling /usr/local/Cellar/kubernetes-cli/1.10.2... (178 files, 52.8MB)
☁  issue [master] gcloud components update

All components are up to date.

此警告已消失。

我刚刚进入 Docker 文件的 bin 文件夹并将 kubectl 移至垃圾箱。

TLDR

/usr/local/bin/kubectl 是由 Docker 安装的 link:ls -l /usr/local/bin/kubectl => /usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl。删除 link 没有副作用并解决了冲突:

rm /usr/local/bin/kubectl

理由

冲突与 Docker 提供的 kubectl 版本有关,因此检查 Docker 文档对此有何评论是有意义的。 https://docs.docker.com/docker-for-mac/#kubernetes

摘录:

In Docker Desktop for Mac 17.12 Edge (mac45) and higher, and 18.06 Stable (mac70) and higher, a standalone Kubernetes server is included that runs on your Mac, so that you can test deploying your Docker workloads on Kubernetes.

The Kubernetes client command, kubectl, is included and configured to connect to the local Kubernetes server.

....

If you installed kubectl with Homebrew, or by some other method, and experience conflicts, remove /usr/local/bin/kubectl.