Search code examples
kubernetesgoogle-compute-enginegcloudgoogle-kubernetes-enginekubectl

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


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"


Solution

  • 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.