我在 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 或创建配置?