[英]How to programmatically generate kubernetes config from GCP service account using python API
I already found the way using gcloud
CLI. 我已经找到了使用
gcloud
CLI的方法。
gcloud auth activate-service-account --key-file=serviceaccount.json
gcloud container clusters get-credentials $clusterName \
--zone=$zone --project=$project
kubectl config view --minify --flatten
However, to eliminate dependency to gcloud cli, Is there any programmatic way to achieve a similar result as above? 但是,要消除对gcloud cli的依赖性,是否有任何编程方式可以实现与上述类似的结果? Preferably using API exposed in Google's python client library.
最好使用Google的python客户端库中公开的API。
My expected result is a portable config file that can be passed to any kubectl --kubeconfig=...
command. 我的预期结果是可移植的配置文件,可以将其传递给任何
kubectl --kubeconfig=...
命令。
update : I have found that the commands I showed above results in a kube config file that still depends on gcloud cli as auth helper, probably to automatically handle token expiration. 更新 :我发现我上面显示的命令生成了一个kube配置文件,该文件仍然依赖gcloud cli作为身份验证帮助程序,可能会自动处理令牌到期。 So, any workarounds are welcome.
因此,欢迎任何解决方法。
I wrote a shell script which basically does exactly what you are expecting. 我写了一个shell脚本,它基本上可以完全满足您的期望。
https://gitlab.com/workshop21/open-source/rbac https://gitlab.com/workshop21/open-source/rbac
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.