docs/docs/self-hosting/deploy-to-cloud/gcp.mdx
MLflow core components include:
This guide walks you through deploying the MLflow server to Google Cloud Run, the backend store to Cloud SQL (PostgreSQL), and the artifact store to Google Cloud Storage (GCS). The guide also covers IAM service accounts, Cloud SQL connectivity, and Cloud Run networking settings. Once deployment is complete, you can access the MLflow web UI through a Cloud Run service URL such as: https://mlflow-<unique-id>.<region>.run.app. Your MLflow client code can connect to the MLflow server by setting the tracking URI to this URL.
The overall deployment architecture is as follows:
The deployment architecture has a couple of advantages:
High Availability
Security by design
Operational Simplicity
Build a docker image using the following Dockerfile:
FROM ghcr.io/mlflow/mlflow:<mlflow-version>-full
RUN pip install google-cloud-storage
The <mlflow-version> in the Dockerfile is a value like v3.10.0.
This docker image is based on the official MLflow docker image, but preinstalls "google-cloud-storage" package which is required by MLflow server to access Google Cloud storage.
In Google Cloud "Artifact Registry" console, create a repository with name of "mlflow-repo", set the repository format to "Docker", the repository path is like <region>-docker.pkg.dev/<gcp-project-name>/mlflow-repo, then build the above docker image and push it to the Google docker repository as follows:
docker build -t <google-docker-repository-path>/mlflow-gcp:v3.10.0 .
docker push <google-docker-repository-path>/mlflow-gcp:v3.10.0
In Google Cloud "Cloud Storage" console, create a bucket with name like "mlflow-artifact-12345" as follows, note that you should turn on "Public access prevention" option to block public access to the bucket.
In Google Cloud "IAM & Admin" console, click "grant access", then assign the "Storage Object User" role to the default compute service account as follows:
In Google Cloud "Cloud SQL" console, click "Create an instance" button to create a "PostgreSQL" instance as follows:
The database connection string used by MLflow is like:
postgresql://<admin-name>:<admin-password>@/<database-name>?host=/cloudsql/<gcp-project-name>:us-central1:<cloud-sql-instance-id>
The default values of "admin-name" and "database-name" are both "postgres".
In Google Cloud "Cloud Run" console, click "Deploy container" button to create a cloud run instance. You need to configure the following items correctly:
server --backend-store-uri <database-connection-string> --artifacts-destination gs://<cloud-storage-bucket-name> --host 0.0.0.0 --port 5000 --disable-security-middlewareAfter created the cloud run instance, you can view the application URL like https://<instance-name>-<unique-id>.<region>.run.app on the instance console page, and you can also view the instance metrics and logs as follows:
MLflow supports basic authentication and authentication with OIDC plugin, the 2 kinds of authentication settings require:
mlflow-gcp image in "Step 1".Use MLflow demo CLI to validate the deployment. Run the command from your own laptop as follows:
mlflow demo --tracking-uri <GCP-cloud-run-application-URL>
then open the application URL in your browser, view the experiment with name "MLflow Demo", and explore GenAI features like traces, evaluation runs, prompt management etc.