【发布时间】:2020-06-27 18:45:51
【问题描述】:
我正在编写这个 Google Cloud Function (Python)
def create_kubeconfig(request):
subprocess.check_output("curl https://sdk.cloud.google.com | bash | echo "" ",stdin=subprocess.PIPE, shell=True )
os.system("./google-cloud-sdk/install.sh")
os.system("gcloud init")
os.system("curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl")
os.system("gcloud container clusters get-credentials **cluster name** --zone us-west2-a --project **project name**")
os.system("gcloud container clusters get-credentials **cluster name** --zone us-west2-a --project **project name**")
conf = KubeConfig()
conf.use_context('**cluster name**')
当我运行代码时,它给了我错误 '无效的 kube-config 文件。 ' kubernetes.config.config_exception.ConfigException:无效的 kube-config 文件。未找到配置。
请帮我解决一下
【问题讨论】:
-
您是否尝试在云函数中运行此代码?
-
@JohnHanley 是的,这是云功能代码的一部分
-
@JohnHanley 这两行不必要的只是试图以某种方式解决问题 os.system("./google-cloud-sdk/install.sh") os.system("gcloud init")它没有帮助
-
@KrisDEV,请记住您处于无服务器环境中。你不知道底层服务器上安装了什么,因为它不是你的服务器,它是无服务器的!就算今天能用,明天也不能用!你只能依赖你的代码,而不是服务器环境!总之,永远不要在无服务器环境(Cloud Function 和 AppEngine 标准)中使用 os 调用!
-
@guillaumeblaquiere 我今天明白了,但我不知道如何处理它,我必须部署一个 yaml 文件来创建 pod 和服务,我必须为此创建一个云功能,并且我找不到任何可以帮助我的东西
标签: python kubernetes google-cloud-platform google-cloud-functions