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

2

1

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"

Popele answered 24/2, 2017 at 5:55 Comment(0)
P
4

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.

Popele answered 24/2, 2017 at 5:55 Comment(0)
B
0

TL;DR; Check that your ~/.kube/config file is correct with kubectl config get-contexts $(kubectl config current-context) command.

Explanation : The following error messages (telling that some core object is not know) are usually caused by a missing current-context entry in the kubectl configuration file.

the server doesn't have a resource type "nodes"
the server doesn't have a resource type "pods"
the server doesn't have a resource type "services"
...

In that case, all contexts are ignored, and kubectl tries to connect to localhost:8080

If you have anything running locally on your machine on port 8080, then you have this weird error message.

Steps to reproduce (from a working configuration) :

$ kubectl get nodes
NAME                              STATUS   ROLES           AGE      VERSION
(.... working access to your kubernetes cluster ...)

$ # EDIT ~/.kube/config file, and remove or comment the current-context entry
$ kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?

$ docker run -d --name dummy_8080 -p 8080:80 nginx
(...)
$ kubectl get nodes
error: the server doesn't have a resource type "nodes"

$ # EDIT ~/.kube/config file, and restore the current-context entry
$ k get nodes
NAME                              STATUS   ROLES           AGE      VERSION
(.... working access to your kubernetes cluster again ...)

$ docker rm -f dummy_8080
Buttocks answered 17/10, 2023 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.