Overview
GCP support in Metaflow includes:- Google Cloud Storage (GCS): Scalable object storage for artifacts and data
- Secret Manager: Secure secrets and credential management
- Container Registry (GCR): Container image storage
- Artifact Registry: Next-generation artifact management
- Kubernetes: Compute execution on Google Kubernetes Engine (GKE)
GCP compute is provided via Kubernetes. See the Kubernetes documentation for compute configuration.
Setup
Prerequisites
- GCP project with billing enabled
- Google Cloud SDK (
gcloud) installed and configured - Metaflow installed:
pip install metaflow - GCP SDK packages:
pip install google-cloud-storage google-cloud-secret-manager
Authentication
Metaflow uses Google Application Default Credentials:Enable Required APIs
Google Cloud Storage
Configure Metaflow to use Google Cloud Storage as the datastore.Configuration
Storage Bucket Setup
GCS Path Format
Metaflow uses standard GCS URI format:gs://my-bucket/metaflow- Bucket “my-bucket” with prefix “metaflow”gs://production-workflows/data- Bucket “production-workflows” with prefix “data”
Using Cloud Storage in Code
Metaflow automatically handles artifact storage:Direct GCS Access
For direct storage operations, use the Google Cloud SDK:GCP Secret Manager
Securely manage secrets and credentials using GCP Secret Manager.Configuration
Secret Manager Setup
Using Secrets
Metaflow’s@secrets decorator integrates with GCP Secret Manager:
Secret Naming
GCP Secret Manager secret names must:- Start with a letter or underscore
- Contain only letters, numbers, underscores, and hyphens
- Be 1-255 characters long
- Examples:
api-key,database_password,API_TOKEN_v2
Secret ID Formats
Metaflow supports multiple secret ID formats:1. Simple Name (Requires Prefix)
2. Name with Version
3. Full Resource Path
4. Full Path with Version
JSON Secrets
Store structured data as JSON:Custom Environment Variable Names
Binary Secrets
Container Registry
Use Google Container Registry or Artifact Registry for Docker images.Setup with GCR
Setup with Artifact Registry
Using Custom Images
Kubernetes Compute
For compute execution on GCP, use Google Kubernetes Engine:See the Kubernetes documentation for detailed GKE setup and configuration.
IAM Permissions
Required IAM roles and permissions:Cloud Storage Access
Role:roles/storage.objectAdmin
Or custom role with:
storage.objects.createstorage.objects.deletestorage.objects.getstorage.objects.liststorage.buckets.get
Secret Manager Access
Role:roles/secretmanager.secretAccessor
Permissions:
secretmanager.secrets.getsecretmanager.versions.access
Container Registry Access
Role:roles/storage.objectViewer (for GCR)
Or for Artifact Registry:
Role: roles/artifactregistry.reader
Best Practices
Storage Optimization
Storage Optimization
- Use appropriate storage class (Standard, Nearline, Coldline, Archive)
- Implement lifecycle management policies
- Enable object versioning for important data
- Use service accounts with minimal permissions
- Monitor storage costs with Cloud Billing reports
Security
Security
- Always use service accounts over user credentials in production
- Enable uniform bucket-level access
- Use VPC Service Controls for enhanced security
- Rotate Secret Manager secrets regularly
- Enable audit logging for storage and secrets
Performance
Performance
- Choose bucket location close to compute resources
- Use Cloud CDN for frequently accessed objects
- Enable requester pays for shared buckets
- Use parallel uploads for large files
- Consider regional vs. multi-regional buckets
Monitoring
Monitoring
- Enable Cloud Storage audit logs
- Monitor Secret Manager access patterns
- Set up alerts for authentication failures
- Track storage usage and costs
- Use Cloud Monitoring for operational metrics
Troubleshooting
Authentication Errors
Authentication Errors
Problem:
DefaultCredentialsError or permission deniedSolutions:- Run
gcloud auth application-default login - Verify service account key file exists and path is correct
- Check workload identity is configured on GKE
- Ensure service account has required IAM roles
- Verify project ID in credentials
GCS Access Denied
GCS Access Denied
Problem: Cannot read or write objectsSolutions:
- Verify Storage Object Admin role is granted
- Check bucket exists and name is correct
- Ensure uniform bucket-level access is enabled
- Verify no organization policies blocking access
- Check VPC Service Controls if enabled
Secret Not Found
Secret Not Found
Problem: Secret retrieval failsSolutions:
- Verify secret name and project ID are correct
- Check Secret Manager API is enabled
- Ensure secret has at least one version
- Verify IAM permissions for secret accessor role
- Check METAFLOW_GCP_SECRET_MANAGER_PREFIX is set correctly
Container Image Pull Failures
Container Image Pull Failures
Problem: Cannot pull image from registrySolutions:
- Verify image name and tag are correct
- Check service account has Artifact Registry Reader role
- Ensure Container Registry API is enabled
- Verify Kubernetes image pull secrets are configured
- Check network connectivity to registry
Configuration Reference
Environment Variables
| Variable | Description | Example |
|---|---|---|
METAFLOW_DEFAULT_DATASTORE | Set to “gs” | gs |
METAFLOW_DATASTORE_SYSROOT_GS | GCS bucket and path | gs://my-bucket/metaflow |
METAFLOW_GCP_SECRET_MANAGER_PREFIX | Secret Manager prefix | projects/123456789/secrets/ |
METAFLOW_DEFAULT_GCP_CLIENT_PROVIDER | Auth provider | gcp-default |
GOOGLE_APPLICATION_CREDENTIALS | Service account key | /path/to/key.json |
GOOGLE_CLOUD_PROJECT | Default project ID | my-project-id |
Python Version Requirements
GCP support requires Python 3.7 or newer.Next Steps
Kubernetes on GKE
Set up compute on Google Kubernetes Engine
Argo Workflows
Deploy production workflows on GCP
Multi-Cloud Overview
Compare cloud platform features
Secrets Management
Advanced secrets management patterns
