1

我在谷歌容器引擎上有兩個kubernetes集羣,但在單獨的Google帳戶(一個使用我公司的電子郵件,另一個使用我的個人電子郵件)。我試圖從一個羣集切換到另一個羣集。我這樣做的:GCE/GKE Kubectl:服務器沒有資源類型「服務」

  1. 登錄與我的其他電子郵件地址

    $ gcloud init

  2. 獲得新kubectl憑據

    gcloud container cluster get-credentials

  3. 測試,看是否連接到新簇

    $ kubectl get po

不過,我仍然沒有能夠得到kubernetes資源在羣集中。我收到的錯誤是:

the server doesn't have a resource type "pods"

回答

1

這是因爲雖然我登錄時使用的新憑證...... kubectl不使用新的憑證發生。爲了改變這種狀況kubectl將用來訪問羣集,你需要運行下面的命令登錄/訪問憑據:

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集羣。

相關問題