简体   繁体   中英

How to programmatically generate kubernetes config from GCP service account using python API

I already found the way using 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? Preferably using API exposed in Google's python client library.

My expected result is a portable config file that can be passed to any kubectl --kubeconfig=... command.


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. So, any workarounds are welcome.

I wrote a shell script which basically does exactly what you are expecting.

https://gitlab.com/workshop21/open-source/rbac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM