GCP
A simple guide to quickly set up a minimal stack on GCP.
This page aims to quickly set up a minimal production stack on GCP. With just a few simple steps you will set up a service account with specifically-scoped permissions that ZenML can use to authenticate with the relevant GCP resources.
While this guide focuses on Google Cloud, we are seeking contributors to create a similar guide for other cloud providers. If you are interested, please create a pull request over on GitHub.
1) Choose a GCP project
In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Make sure a billing account is attached to this project to allow the use of some APIs.
This is how you would do it from the CLI if this is preferred.
gcloud projects create <PROJECT_ID> --billing-project=<BILLING_PROJECT>2) Enable GCloud APIs
The following APIs will need to be enabled within your chosen GCP project.
Cloud Functions API # For the vertex orchestrator
Cloud Run Admin API # For the vertex orchestrator
Cloud Build API # For the container registry
Artifact Registry API # For the container registry
Cloud Logging API # Generally needed
3) Create a dedicated service account with least privilege permissions
Create a custom service account with only the minimum required permissions instead of using broad predefined roles. This follows the principle of least privilege:
For ZenML Client Operations (where pipelines are submitted):
Vertex AI User (
roles/aiplatform.user) - for creating and managing Vertex AI pipeline jobsStorage Object Admin (
roles/storage.objectAdmin) - for artifact store operationsCloud Functions Developer (
roles/cloudfunctions.developer) - for scheduled pipelines (if using scheduling)
For Pipeline Workload Operations (where pipeline steps run): Create a separate service account for the actual pipeline execution:
Vertex AI Service Agent (
roles/aiplatform.serviceAgent) - for running Vertex AI pipelinesStorage Object Admin (
roles/storage.objectAdmin) - for accessing artifacts during pipeline execution
More Granular Permissions (Alternative): If you prefer even more granular control, you can create custom roles with these specific permissions:
For GCS Access:
For Vertex AI Access:
For Container Registry Access:
This approach significantly reduces security risks by limiting permissions to only what's necessary for ZenML operations.
4) Create the service accounts and assign roles
Create the service accounts and assign the least privilege roles:
bash\n# Create client service account\ngcloud iam service-accounts create zenml-client \\\n --display-name=\"ZenML Client Service Account\" \\\n --description=\"Service account for ZenML client operations\"\n\n# Create workload service account\ngcloud iam service-accounts create zenml-workload \\\n --display-name=\"ZenML Workload Service Account\" \\\n --description=\"Service account for ZenML pipeline execution\"\n\n# Assign roles to client service account\ngcloud projects add-iam-policy-binding <PROJECT_ID> \\\n --member=\"serviceAccount:zenml-client@<PROJECT_ID>.iam.gserviceaccount.com\" \\\n --role=\"roles/aiplatform.user\"\n\ngcloud projects add-iam-policy-binding <PROJECT_ID> \\\n --member=\"serviceAccount:zenml-client@<PROJECT_ID>.iam.gserviceaccount.com\" \\\n --role=\"roles/storage.objectAdmin\"\n\n# Assign roles to workload service account\ngcloud projects add-iam-policy-binding <PROJECT_ID> \\\n --member=\"serviceAccount:zenml-workload@<PROJECT_ID>.iam.gserviceaccount.com\" \\\n --role=\"roles/aiplatform.serviceAgent\"\n\ngcloud projects add-iam-policy-binding <PROJECT_ID> \\\n --member=\"serviceAccount:zenml-workload@<PROJECT_ID>.iam.gserviceaccount.com\" \\\n --role=\"roles/storage.objectAdmin\"\n\n\n### 5) Create a JSON Key for your client service account
This json file will allow the service account to assume the identity of this service account. You will need the filepath of the downloaded file in the next step.
6) Create a Service Connector within ZenML
The service connector will allow ZenML and other ZenML components to authenticate themselves with GCP.
7) Create Stack Components
Artifact Store
Before you run anything within the ZenML CLI, head on over to GCP and create a GCS bucket, in case you don't already have one that you can use. Once this is done, you can create the ZenML stack component as follows:
Orchestrator
This guide will use Vertex AI as the orchestrator to run the pipelines. As a serverless service Vertex is a great choice for quick prototyping of your MLOps stack. The orchestrator can be switched out at any point in the future for a more use-case- and budget-appropriate solution.
Container Registry
8) Create Stack
And you're already done!
Just like that, you now have a fully working GCP stack ready to go. Feel free to take it for a spin by running a pipeline on it.
Cleanup
If you do not want to use any of the created resources in the future, simply delete the project you created.
Best Practices for Using a GCP Stack with ZenML
When working with a GCP stack in ZenML, consider the following best practices to optimize your workflow, enhance security, and improve cost-efficiency. These are all things you might want to do or amend in your own setup once you have tried running some pipelines on your GCP stack.
Use IAM and Least Privilege Principle
Always adhere to the principle of least privilege when setting up IAM roles. The guide above demonstrates this by using specific roles instead of broad "Editor" or "Owner" permissions:
Vertex AI User instead of broad compute permissions
Storage Object Admin scoped to specific buckets instead of project-wide storage access
Separate service accounts for client operations vs. workload execution
Custom roles with granular permissions when predefined roles are too broad
Regularly review and audit your IAM roles to ensure they remain appropriate and secure. Use Google Cloud's IAM Recommender to identify and remove unused permissions.
Leverage GCP Resource Labeling
Implement a consistent labeling strategy for your GCP resources. To label a GCS bucket, for example:
This command adds two labels to the bucket:
A label with key "project" and value "zenml"
A label with key "environment" and value "production"
You can add or update multiple labels in a single command by separating them with commas.
To remove a label, set its value to null:
These labels will help you with billing and cost allocation tracking and also with any cleanup efforts.
To view the labels on a bucket:
This will display all labels currently set on the specified bucket.
Implement Cost Management Strategies
Use Google Cloud's Cost Management tools to monitor and manage your spending. To set up a budget alert:
Navigate to the Google Cloud Console
Go to Billing > Budgets & Alerts
Click "Create Budget"
Set your budget amount, scope (project, product, etc.), and alert thresholds
You can also use the gcloud CLI to create a budget:
Set up cost allocation labels to track expenses related to your ZenML projects in the Google Cloud Billing Console.
Implement a Robust Backup Strategy
Regularly backup your critical data and configurations. For GCS, for example, enable versioning and consider using cross-region replication for disaster recovery.
To enable versioning on a GCS bucket:
To set up cross-region replication:
By following these best practices and implementing the provided examples, you can create a more secure, efficient, and cost-effective GCP stack for your ZenML projects. Remember to regularly review and update your practices as your projects evolve and as GCP introduces new features and services.
Last updated
Was this helpful?