GCE/GKE Kubectl:服务器没有资源类型"services"
GCE/GKE Kubectl: the server doesn't have a resource type "services"
我在 google 容器引擎上有两个 kubernetes 集群,但在单独的 google 帐户上(一个使用我公司的电子邮件,另一个使用我的个人电子邮件)。我试图从一个集群切换到另一个集群。我通过以下方式做到了这一点:
使用我的其他电子邮件地址登录
$ gcloud init
获取新的 kubectl 凭据
gcloud container cluster get-credentials
测试是否连接到新集群
$ kubectl get po
但是我还是获取不到集群中的kubernetes资源。我收到的错误是:
the server doesn't have a resource type "pods"
发生这种情况是因为尽管我使用新凭据登录...kubectl 没有使用新凭据。为了更改 kubectl 将用于访问您的集群的 login/access 凭据,您需要 运行 以下命令:
gcloud auth application-default login
您将收到以下回复:
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth
redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&prompt=select_account&respons
e_type=code&client_id=...&
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&access_type=offline
Credentials saved to file: [/Users/.../.config/gcloud/application_default_credentials.json]
These credentials will be used by any library that requests
Application Default Credentials.
然后获取集群凭证
gcloud container clusters get-credentials [cluster name/id]
您现在应该可以使用 kubectl 访问集群了。
我在 google 容器引擎上有两个 kubernetes 集群,但在单独的 google 帐户上(一个使用我公司的电子邮件,另一个使用我的个人电子邮件)。我试图从一个集群切换到另一个集群。我通过以下方式做到了这一点:
使用我的其他电子邮件地址登录
$ gcloud init
获取新的 kubectl 凭据
gcloud container cluster get-credentials
测试是否连接到新集群
$ kubectl get po
但是我还是获取不到集群中的kubernetes资源。我收到的错误是:
the server doesn't have a resource type "pods"
发生这种情况是因为尽管我使用新凭据登录...kubectl 没有使用新凭据。为了更改 kubectl 将用于访问您的集群的 login/access 凭据,您需要 运行 以下命令:
gcloud auth application-default login
您将收到以下回复:
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth
redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&prompt=select_account&respons
e_type=code&client_id=...&
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&access_type=offline
Credentials saved to file: [/Users/.../.config/gcloud/application_default_credentials.json]
These credentials will be used by any library that requests
Application Default Credentials.
然后获取集群凭证
gcloud container clusters get-credentials [cluster name/id]
您现在应该可以使用 kubectl 访问集群了。