【问题标题】:gcp python function - delete kubernetes namespaces, and get .kube/config filegcp python 函数 - 删除 kubernetes 命名空间,并获取 .kube/config 文件
【发布时间】:2020-06-04 21:18:06
【问题描述】:

我想在 google 函数中创建一个 python 脚本 - 删除给定的命名空间, 但是有两个问题 - 函数无法访问全局 kubeconfig 文件 - 我收到没有配置文件的错误 所以: 我创建了配置文件,将其上传到存储桶并尝试从KubeConfig() 的存储桶中使用它 这样:

storage_client = storage.Client()
bucket = storage_client.get_bucket("kyc-tfstate-staging")
blob=bucket.get_blob("storage/config2")
conf = KubeConfig(blob)
print(conf)

我得到了下一个输出:

kubeconfig.kubeconfig.KubeConfig object at 0x7feee1868a58

之后我尝试打印我拥有的所有命名空间:

v1 = kubernetes.client.CoreV1Api()
response = v1.list_namespace()
print(response)

我得到了下一个错误:

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /api/v1/namespaces (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe49e098a90>: Failed to establish a new connection: [Errno 111] Connection refused',))

【问题讨论】:

    标签: python kubernetes google-cloud-platform google-kubernetes-engine bucket


    【解决方案1】:

    这似乎是一个已知问题,但正如 here 所见,必须在 3.0 版中修复。此外,作为一种解决方法,您可以使用以下方法:

        os.environ['KUBERNETES_SERVICE_HOST'] = 'kubernetes'
        config.load_incluster_config()
    

    【讨论】:

      猜你喜欢
      • 2022-10-04
      • 2021-09-18
      • 2021-09-12
      • 2019-08-14
      • 2019-09-15
      • 2022-08-19
      • 1970-01-01
      • 2022-07-07
      • 2018-12-04
      相关资源
      最近更新 更多