【发布时间】:2019-03-13 05:28:04
【问题描述】:
我在 GKE 上有一个 Kubernetes 集群。即使在正确设置了 KUBECONFIG="/tmp/kubeconfigxvz" 之后,当我执行 kubectl get pods 时,命令也会失败并出现以下错误
bash-4.3# kubectl get pods
Unable to connect to the server: error executing access token command
"/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=exit
status 1 output= stderr=ERROR: (gcloud.config.config-helper) You do not
currently have an active account selected.
Please run:
$ gcloud auth login
to obtain new credentials, or if you have already logged in with a
different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
当我设置CLOUDSDK_CONFIG=/tmp/customdir 时,命令开始工作。
如何使用 go 客户端实现相同的功能?
=== 更新 ===
创建 go 客户端时,我将正确的文件指针传递给此函数
clientcmd.BuildConfigFromFlags("", *tmpKubeConfigFile) 其中tmpKubeConfigFile 指向/tmp/kubeconfigxvz。
但我认为这还不够,go-client 还需要来自CLOUDSDK_CONFIG 目录的更多信息,我认为它需要会话信息或凭据之类的。
创建go-client时是否也可以传递这个CLOUDSDK_CONFIG?
BuildConfigFromFlags 接收指向 kubeconfig 文件的指针并返回一个 config 对象,该对象可以传递给创建客户端的 kubernetes.NewForConfig(config)。是否有可能或是否存在类似的功能来传递 CLOUDSDK_CONFIG 并返回 go-client 或创建配置?
【问题讨论】:
标签: kubernetes kubernetes-go-client