从kubernetes孵化器/客户端python连接到gke群集时出错

从kubernetes孵化器/客户端python连接到gke群集时出错,python,authentication,kubernetes,google-kubernetes-engine,Python,Authentication,Kubernetes,Google Kubernetes Engine,我正在尝试使用kubernetes孵化器/客户端python库连接到我的gke集群。我只运行基本查询: from kubernetes import client, config # Configs can be set in Configuration class directly or using helper utility config.load_kube_config() v1 = client.CoreV1Api() print("Listing pods with their IP

我正在尝试使用kubernetes孵化器/客户端python库连接到我的gke集群。我只运行基本查询:

from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
我得到一个错误:

--------------------------------------------------------------------------
RefreshError  Traceback (most recent call last)
<ipython-input-1-40695f414daf> in <module>()
      2 
      3 # Configs can be set in Configuration class directly or using helper utility
----> 4 config.load_kube_config()
      5 
      6 v1 = client.CoreV1Api()

/usr/local/lib/python2.7/distpackages/kubernetes/config/kube_config.pyc in 
load_kube_config(config_file, context, client_configuration, 
persist_config)
    359         config_file, active_context=context,
    360         client_configuration=client_configuration,    
--> 361         config_persister=config_persister).load_and_set()
    362 
    363 

/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in load_and_set(self)
    251 
    252     def load_and_set(self):
--> 253         self._load_authentication()
    254         self._load_cluster_info()
    255         self._set_config()

    /usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in 
    _load_authentication(self)
        174         if not self._user:
        175             return

/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in _load_gcp_token(self)
    194                  _is_expired(provider['config']['expiry']))):
    195             # token is not available or expired, refresh it
--> 196             self._refresh_gcp_token()
    197 
    198         self.token = "Bearer %s" % provider['config']['access-token']

/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in _refresh_gcp_token(self)
    203             self._user['auth-provider'].value['config'] = {}
    204         provider = self._user['auth-provider']['config']
--> 205         credentials = self._get_google_credentials()
    206         provider.value['access-token'] = credentials.token
    207         provider.value['expiry'] = format_rfc3339(credentials.expiry)

/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in _refresh_credentials()
    133             credentials, project_id = google.auth.default()
    134             request = google.auth.transport.requests.Request()
--> 135             credentials.refresh(request)
    136             return credentials
    137 

/usr/local/lib/python2.7/dist-packages/google/oauth2/service_account.pyc in refresh(self, request)
    320         assertion = self._make_authorization_grant_assertion()
    321         access_token, expiry, _ = _client.jwt_grant(
--> 322             request, self._token_uri, assertion)
    323         self.token = access_token
    324         self.expiry = expiry

/usr/local/lib/python2.7/dist-packages/google/oauth2/_client.pyc in jwt_grant(request, token_uri, assertion)
    141     }
    142 
--> 143     response_data = _token_endpoint_request(request, token_uri, body)
    144 
    145     try:

/usr/local/lib/python2.7/dist-packages/google/oauth2/_client.pyc in _token_endpoint_request(request, token_uri, body)
    107 
    108     if response.status != http_client.OK:
--> 109         _handle_error_response(response_body)
    110 
    111     response_data = json.loads(response_body)

/usr/local/lib/python2.7/dist-packages/google/oauth2/_client.pyc in _handle_error_response(response_body)
     57 
     58     raise exceptions.RefreshError(
---> 59         error_details, response_body)
     60 
     61 

RefreshError: ('invalid_scope: Empty or missing scope not allowed.', u'{\n  "error" : "invalid_scope",\n  "error_description" : "Empty or missing scope not allowed."\n}')
--------------------------------------------------------------------------
RefreshError回溯(最近一次呼叫上次)
在()
2.
3#配置可以直接在配置类中设置,也可以使用helper实用程序设置
---->4 config.load_kube_config()
5.
6 v1=client.CoreV1Api()
/中的usr/local/lib/python2.7/distpackages/kubernetes/config/kube_config.pyc
加载配置(配置文件、上下文、客户端配置、,
持久化(配置)
359配置文件,活动上下文=上下文,
360客户端配置=客户端配置,
-->361 config\u persister=config\u persister).加载和设置()
362
363
/加载集(self)中的usr/local/lib/python2.7/dist-packages/kubernetes/config/kube\u config.pyc
251
252 def加载_和_设置(自):
-->253自加载身份验证()
254自我加载群集信息()
255 self.\u set\u config()
/中的usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc
_加载\u身份验证(自)
174如果不是自己的用户:
175返回
/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in_load_gcp_令牌(self)
194 _已过期(提供程序['config']['expirement']):
195#令牌不可用或已过期,请刷新它
-->196自我更新gcp令牌()
197
198 self.token=“承载%s”%provider['config']['access-token']
/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube_config.pyc in_refresh_gcp_令牌(self)
203 self.\u用户['auth-provider'].值['config']={}
204 provider=self.\u用户['auth-provider']['config']
-->205凭证=self.\u获取\u谷歌\u凭证()
206 provider.value['access-token']=credentials.token
207 provider.value['expiry']=格式\u rfc3339(凭证.expiry)
/usr/local/lib/python2.7/dist-packages/kubernetes/config/kube\u config.pyc in_refresh\u credentials()
133凭证,project_id=google.auth.default()
134 request=google.auth.transport.requests.request()
-->135.刷新(请求)
136返回凭证
137
/刷新中的usr/local/lib/python2.7/dist-packages/google/oauth2/service_account.pyc(self,request)
320 assertion=self.\u make\u authorization\u grant\u assertion()
321访问\u令牌,到期,\u=\u client.jwt\u授权(
-->322请求,自身。\u令牌\u uri,断言)
323 self.token=访问令牌
324自我失效=失效
/jwt\u grant中的usr/local/lib/python2.7/dist-packages/google/oauth2//u client.pyc(请求、令牌uri、断言)
141     }
142
-->143响应\数据=\令牌\端点\请求(请求,令牌\ uri,正文)
144
请尝试:
/usr/local/lib/python2.7/dist-packages/google/oauth2//u client.pyc in\u token\u endpoint\u请求(请求,token\u uri,body)
107
108如果响应。状态!=http_client.OK:
-->109手柄错误响应(响应体)
110
111 response_data=json.load(response_body)
/usr/local/lib/python2.7/dist-packages/google/oauth2//u client.pyc in\u handle\u error\u response(response\u body)
57
58引发异常。刷新错误(
--->59错误(详细信息,响应(正文)
60
61
RefreshError:(“无效的\u作用域:不允许空白或缺少作用域。”,u'{\n“错误”:“无效的\u作用域”,\n“错误描述”:“不允许空白或缺少作用域。”\n})

我以为我的kube.config文件有问题。所以我删除了它并再次创建了集群,以便重新创建一个新的kube.config文件。这个问题仍然存在。你能帮我一下吗

这是您的Google云平台凭据的问题。找不到它们,您无法与服务交互。关于如何设置这些。将
GOOGLE\u APPLICATION\u CREDENTIALS
环境变量指向您的凭据文件,或通过SDK进行身份验证