错误:gcloud崩溃(CannotConnectToMetadataServerException):<urlopen error =“”[errno =“” - 2] =“”name =“”does =“”not =“”resolve =“”>

时间:2018-04-03 19:06:32

标签: kubernetes gcloud circleci

我在使用命令gcloud容器集群get-credentials配置我的容器以指向我的Kubernetes集群时遇到问题。我收到以下错误。

ERROR: gcloud crashed (CannotConnectToMetadataServerException): <urlopen error [Errno -2] Name does not resolve>

If you would like to report this issue, please run the following command:
  gcloud feedback

To check gcloud for common problems, please run the following command:
  gcloud info --run-diagnostics

增强日志记录:

CannotConnectToMetadataServerException: <urlopen error [Errno -2] Name does not resolve>
2018-04-10 18:00:42,625 ERROR    ___FILE_ONLY___ BEGIN CRASH STACKTRACE
Traceback (most recent call last):
  File "/google-cloud-sdk/lib/googlecloudsdk/gcloud_main.py", line 147, in main
    gcloud_cli.Execute()
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 818, in Execute
    self._HandleAllErrors(exc, command_path_string, specified_arg_names)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 856, in _HandleAllErrors
    exceptions.HandleError(exc, command_path_string, self.__known_error_handler)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/exceptions.py", line 526, in HandleError
    core_exceptions.reraise(exc)
  File "/google-cloud-sdk/lib/googlecloudsdk/core/exceptions.py", line 111, in reraise
    six.reraise(type(exc_value), exc_value, tb)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 792, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 751, in Run
    self._parent_group.RunGroupFilter(tool_context, args)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 692, in RunGroupFilter
    self._parent_group.RunGroupFilter(context, args)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 693, in RunGroupFilter
    self._common_type().Filter(context, args)
  File "/google-cloud-sdk/lib/surface/container/__init__.py", line 71, in Filter
    context['api_adapter'] = api_adapter.NewAPIAdapter('v1')
  File "/google-cloud-sdk/lib/googlecloudsdk/api_lib/container/api_adapter.py", line 147, in NewAPIAdapter
    return NewV1APIAdapter()
  File "/google-cloud-sdk/lib/googlecloudsdk/api_lib/container/api_adapter.py", line 151, in NewV1APIAdapter
    return InitAPIAdapter('v1', V1Adapter)
  File "/google-cloud-sdk/lib/googlecloudsdk/api_lib/container/api_adapter.py", line 172, in InitAPIAdapter
    api_client = core_apis.GetClientInstance('container', api_version)
  File "/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/apis.py", line 297, in GetClientInstance
    api_name, api_version, no_http, _CheckResponse, enable_resource_quota)
  File "/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/apis_internal.py", line 153, in _GetClientInstance
    http_client = http.Http(enable_resource_quota=enable_resource_quota)
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/http.py", line 64, in Http
    creds = store.LoadIfEnabled()
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 281, in LoadIfEnabled
    return Load()
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 348, in Load
    cred = STATIC_CREDENTIAL_PROVIDERS.GetCredentials(account)
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 162, in GetCredentials
    cred = provider.GetCredentials(account)
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 214, in GetCredentials
    if account in c_gce.Metadata().Accounts():
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce.py", line 127, in Accounts
    gce_read.GOOGLE_GCE_METADATA_ACCOUNTS_URI + '/')
  File "/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 289, in DecoratedFunction
    exceptions.reraise(to_reraise[1], tb=to_reraise[2])
  File "/google-cloud-sdk/lib/googlecloudsdk/core/exceptions.py", line 111, in reraise
    six.reraise(type(exc_value), exc_value, tb)
  File "/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 159, in TryFunc
    return func(*args, **kwargs), None
  File "/google-cloud-sdk/lib/googlecloudsdk/core/credentials/gce.py", line 52, in _ReadNoProxyWithCleanFailures
    raise CannotConnectToMetadataServerException(e)
CannotConnectToMetadataServerException: <urlopen error [Errno -2] Name does not resolve>

为了给出一些颜色,我们每次将代码推送到github时都会向CircleCI启动构建。但是,我们有一个我们称之为内部belushi的容器,我们用它来运行我们的整个基础设施。这个容器里面装有gcloud。 CircleCI基础设施在AWS上,当他们启动belushi容器时,我们实际运行gcloud get-credentials,将belushi容器指向我们在google cloud中的项目,该项目配置了kubernetes集群,我们在该集群中运行所有功能CI测试。所以我们需要belushi pod配置到ci项目中继续前进。

奇怪的是belushi:最新的图像总是正确配置;然而,当我们在belushi工作时,我们经常分支并创建一个新图像来运行测试。所以例如,我将在belushi创建一个分支,然后有一个1234567的新哈希,所以我们将旋转belushi:1234567图像并尝试运行的东西,我们做的第一件事就是配置它指向ci项目;但是,我们得到了元数据解决问题。

我觉得它与DNS相关,或者元数据服务器不允许belushi的新图像立即与之通信。在我重试它之后,它最终会正确配置(没有任何代码更改)。所以我想知道元数据服务器是否由于某种原因拒绝它,或者它可能在AWS上因某些未知原因而无法解决。

1 个答案:

答案 0 :(得分:0)

您可以做的第一件事就是,当您收到此错误时,请尝试以下操作:

curl -H "Metadata-Flavor:Google" http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/

元数据服务器应立即响应您的服务帐户元数据。

您的容器是否支持任何类型的http代理?