1

我試圖建立一個持續集成的工作,將部署到kubernetes /谷歌容器引擎從詹金斯的工作gcloud SDK。 jenkins服務器受到相對嚴格的控制,所以我無法安裝插件。授權給Kubernetes在谷歌集裝箱引擎沒有從詹金斯

我從谷歌雲IAM服務器帳戶JSON密鑰文件。

我目前正試圖下載從那裏的谷歌雲SDK和權威性,但我沒有任何運氣(這一點,如果從Jenkinsfile):

sh 'export KUBECONFIG=$(pwd)/.kubeconfig' 
sh 'export GOOGLE_APPLICATION_CREDENTIALS=$JSON' 
sh 'google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=$JSON' 
sh 'google-cloud-sdk/bin/gcloud config set core/project proj-1' 
sh 'google-cloud-sdk/bin/gcloud container clusters list' 
sh 'google-cloud-sdk/bin/gcloud container clusters get-credentials clust-1 --zone us-east1-c' 
sh 'kubectl get pods' 

我收到錯誤消息: 錯誤:谷歌:找不到默認憑據。有關更多信息,請參閱https://developers.google.com/accounts/docs/application-default-credentials。 我還需要能夠執行gcloud docker push,因此使用gcloud即可。

回答

1

有解決此問題,一個神祕的GitHub的問題:

https://github.com/kubernetes/kubernetes/issues/30617

根據這個問題,一切,我一直在做應該工作:

Previously, gcloud would have configured kubectl to use the cluster's static client certificate to authenticate. Now, gcloud is configuring kubectl to use the service account's credentials.

Kubectl is just using the Application Default Credentials library, and it looks like this is part of the ADC flow for using a JSON-key service account. I'll see if there is a way that we could make this nicer.

If you don't want to add the export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json" to your flow, you can reenable the old way (use the client cert) by setting the cloudsdk container/use_client_certificate property to true. Either:

gcloud config set container/use_client_certificate True

or

export CLOUDSDK_CONTAINER_USE_CLIENT_CERTIFICATE=True

我用的是GOOGLE_APPLICATION_CREDENTIALS變量,但唉,沒有工作。我嘗試了上面的「gcloud config set」選項,但那也沒有奏效。最後,我使用了env變量CLOUDSDK_CONTAINER_USE_CLIENT_CERTIFCIATE,實際上最終確實起作用了。