简体   繁体   English

如何使用python API从GCP服务帐户以编程方式生成kubernetes配置

[英]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.

相关问题 GCP Kube.netes 不使用服务帐户来拉取 docker 个图像 - GCP Kubernetes not using service account for pulling docker images 如何将GCP服务帐户添加到Kubernetes工作负载/项目 - How To Add GCP Service Account To Kubernetes Workload/Project 如何向kubernetes工作负载提供自定义GCP服务帐户? - How do I present a custom GCP service account to kubernetes workloads? 在 GCP 中使用 python Kubernetes api 的身份验证不起作用 - Authentication using python Kubernetes api in GCP is not working 使用 python api 从 GCP 管理 Kubernetes 集群 - Managing Kubernetes cluster from GCP with python api 使用 Python API 以编程方式克隆 Kubernetes 对象 - Clone Kubernetes objects programmatically using the Python API 如何通过名称从vm访问GCP中的kubernetes服务? - How to access a kubernetes service in GCP by name from a vm? 由于 GCP 服务帐户,Pod 在 Kubernetes 中出现了 CrashLoopBackOff - Pod got CrashLoopBackOff in Kubernetes because of GCP service account Vault 服务帐户是否应使用默认服务帐户 API 令牌向 Kube.netes 进行身份验证? - Should the Vault Service Account Be Using the Default Service Account API Token to Authenticate to Kubernetes? 如何删除kubernetes中的服务帐户? - How to delete a service account in kubernetes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM