1

Ich versuche einen Continuous Integration Job einzurichten, der von einem Jenkins-Job in der kubernetes/google Container Engine bereitgestellt wird. Der Jenkins-Server ist relativ streng kontrolliert, daher kann ich keine Plugins installieren.Autorisierung für Kubernetes auf Google Container Engine ohne gcloud SDK von Jenkins

Ich habe eine JSON-Schlüsseldatei für ein Serverkonto von Google Cloud IAM.

Ich bin derzeit versucht, den Google Cloud sdk und Auth von dort herunterladen, aber habe kein Glück (diese Option, wenn von einem 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' 

ich die Fehlermeldung bekommen: Fehler: google: konnte keine Standardanmeldeinformationen finden. Weitere Informationen finden Sie unter https://developers.google.com/accounts/docs/application-default-credentials. Ich muss auch in der Lage sein, einen gcloud docker push zu machen, also ist die Verwendung von gcloud in Ordnung.

Antwort

1

Es gibt ein kryptisches Github Problem, um dieses Verhalten:

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

Nach dieser Ausgabe, alles, was ich soll getan habe arbeiten:

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

ich die GOOGLE_APPLICATION_CREDENTIALS Variable wurde mit, aber ach, hat nicht funktioniert. Ich habe die Option "gcloud config set" oben versucht, aber das hat auch nicht funktioniert. Schließlich habe ich die env-Variable CLOUDSDK_CONTAINER_USE_CLIENT_CERTIFCIATE verwendet, die tatsächlich endlich funktioniert hat.

Verwandte Themen