发生这种情况是因为虽然我使用新凭据登录... 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 访问集群了。