GCE/GKE Kubectl: the server doesn't have a resource type “services”

空扰寡人 提交于 2019-12-08 03:54:40

问题


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:

  1. Logging in with my other email address

    $ gcloud init

  2. Getting new kubectl credentials

    gcloud container cluster get-credentials

  3. Test to see if connected to new cluster

    $ kubectl get po

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"


回答1:


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.

Then get cluster credentials

gcloud container clusters get-credentials [cluster name/id]

You should now be able to access the cluster using kubectl.



来源:https://stackoverflow.com/questions/42431749/gce-gke-kubectl-the-server-doesnt-have-a-resource-type-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!