在GCP中使用多个kubernetes集群时,我想在切换gcloud配置时自动获取集群凭据。
我已经使用gcloud config configurations create [config-name]
为gcloud创建了几种配置,并设置了所需的内容,特别是gcloud config set container/cluster [cluster-name]
。
当我使用gcloud config configurations activate [config-name]
切换配置时,一切正常,除了我没有获得针对该配置配置的集群的凭据。相反,我需要运行gcloud container clusters get-credentials [cluster-name]
。
激活gcloud配置时,有什么方法可以自动获取集群的凭据?
答案 0 :(得分:0)
我认为不是。
gcloud
和kubectl
是不同的工具,并且各自维护自己的配置。
gcloud container custers get-credentials
是一个桥接帮助程序,它使用kubectl
身份验证帮助程序配置~/.kube/config
配置(通常位于gcloud
文件中),以方便访问Kubernetes Engine集群。但是,否则这两个工具是无关的。
请看一下我写的这篇文章,其中介绍了如何在kubectl
中使用不同的配置。这不是您想要的,但我希望它会有用:
https://medium.com/google-cloud/context-light-gcloud-and-kubectl-89185d38ce82