GCE/GKE Kubectl:服务器没有资源类型“服务" [英] GCE/GKE Kubectl: the server doesn't have a resource type "services"
问题描述
我在Google容器引擎上有两个kubernetes集群,但是在单独的google帐户上(一个使用我公司的电子邮件,另一个使用我的个人电子邮件).我试图从一个群集切换到另一个群集.我这样做的方式是:
I have two kubernetes clusters on google container engine but on seperate google accounts (one using my company's email and another using my personal email). I attempted to switch from one cluster to another. I did this by:
-
使用我的其他电子邮件地址登录
Logging in with my other email address
$ gcloud init
获取新的kubectl凭据
Getting new kubectl credentials
gcloud container cluster get-credentials
测试以查看是否已连接到新集群
Test to see if connected to new cluster
$ kubectl get po
但是,我仍然无法在集群中获得kubernetes资源.我收到的错误是:
However, I was still not able to get the kubernetes resources in the cluster. The error I received was:
the server doesn't have a resource type "pods"
推荐答案
发生这种情况的原因是,尽管我使用新的凭据登录... kubectl并未使用新的凭据.为了更改kubectl将用于访问集群的登录/访问凭据,您需要运行以下命令:
This occurs because although I logged in with the new credentials... kubectl isn't using the new credentials. In order to change the login/access credentials that kubectl will use to access your cluster you need to run the following command:
gcloud auth application-default login
然后您将收到以下响应:
You will then get the following response:
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访问集群.
You should now be able to access the cluster using kubectl.
这篇关于GCE/GKE Kubectl:服务器没有资源类型“服务"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!