无法登录 Openshift 集群

问题描述

升级 kubectl 后,我无法登录 Openshift 集群。

当我尝试使用 oc login 命令登录时,它会恢复以下错误消息:

Error: unkNown command "login" for "kubectl"

 Did you mean this?

 logs
 plugin

 Run 'kubectl --help' for usage.

以下是我遇到登录问题的机器版本的一些详细信息

# kubectl version

 Client Version: version.Info{Major:"1",Minor:"18",GitVersion:"v1.18.0",GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8",GitTreeState:"clean",BuildDate:"2020-03-25T14:58:59Z",GoVersion:"go1.13.8",Compiler:"gc",Platform:"linux/amd64"}

 error: You must be logged in to the server (the server has asked for the client to provide credentials)

以下是我没有问题的机器版本的一些详细信息,我可以登录并且没有升级 kubectl 版本

# kubectl version

 Client Version: version.Info{Major:"",Minor:"",GitVersion:"v0.0.0-master+$Format:%h$",GitCommit:"$Format:%H$",GitTreeState:"",BuildDate:"1970-01-01T00:00:00Z",GoVersion:"go1.12.12",Platform:"linux/amd64"}

 Server Version: version.Info{Major:"1",Minor:"16+",GitVersion:"v1.16.2+f2384e2",GitCommit:"f2384e2",BuildDate:"2020-06-16T03:21:27Z",Platform:"linux/amd64"}

补充:我已经通过降级 kubectl 版本进行了检查,但是在我无法使用 oc login 登录的那台机器上遇到同样的错误

解决方法

您似乎以某种方式将 oc 符号链接到 kubectl

如您所见,kubectl 没有 login 方法,您需要实际使用 oc CLI 工具登录到您的 OpenShift 集群。这将获得与 OpenShift API 对话所需的正确令牌。

或者,您可以通过 OpenShift Web 控制台(右上角,“复制登录命令”或类似内容)获取必要的令牌。