kubernetesdockerfilegcloudgoogle-cloud-vertex-aigoogle-gemini

Docker image running in k8s which needs gcloud auth credentials


I need run a python app in docker container on k8s. This app needs to use gcloud stuff like gemini-2.0-flash, google_vertexai and

vertexai.init(project=os.environ.get("GOOGLE_CLOUD_PROJECT"), location=os.environ.get("GOOGLE_CLOUD_LOCATION"))

I can install the gcloud CLI in Dockerfile. What's next after that? Any reference?


Solution

  • As commented by @DazWilkin, your issue could be resolved if you leverage the instructions to use ADC for local development. Using your user credentials (Google Account) or impersonating a Service Account will create a key (on Linux in ${HOME}/.config/gcloud/application_default_credentials.json) that you can (volume) mount into the container, then reference using the environment variable GOOGLE_APPLICATION_CREDENTIALS. You need only have gcloud installed on the host not the container.

    Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future. Feel free to edit this answer for additional information.