Rasmus
08/01/2025, 11:17 AMMarvin
08/01/2025, 11:17 AMMarvin
08/01/2025, 11:19 AMbash
prefect work-pool inspect "your-cloud-run-pool"
This will show you the current configuration and limits set at the work pool level, which your deployment-specific settings will override.Rasmus
08/01/2025, 11:22 AMMarvin
08/01/2025, 11:22 AMMarvin
08/01/2025, 11:25 AMprefect.yaml
file. Here's how to structure it:
yaml
deployments:
- name: your-deployment-name
version: null
tags: []
description: null
schedule: null
flow_name: null
entrypoint: null
parameters: {}
work_pool:
name: your-cloud-run-pool
job_variables:
resource_limits:
cpu: "2"
memory: "4Gi"
For multiple deployments with different resource requirements, you can specify them individually:
yaml
deployments:
- name: small-deployment
work_pool:
name: your-cloud-run-pool
job_variables:
resource_limits:
cpu: "1"
memory: "2Gi"
- name: large-deployment
work_pool:
name: your-cloud-run-pool
job_variables:
resource_limits:
cpu: "4"
memory: "8Gi"
Important notes:
1. The resource_limits
configuration will override the work pool defaults only for the specific deployment(s)
2. Valid CPU values for Cloud Run: "1", "2", or "4"
3. Memory values should include units (e.g., "512Mi", "1Gi", "2Gi", "4Gi", etc.)
4. Make sure the values are within Cloud Run's supported limits for your region
You can apply these changes by running:
bash
prefect deploy --all
Or for a specific deployment:
bash
prefect deploy -n your-deployment-name
To verify the configuration was applied correctly, you can check the deployment details in the Prefect UI or use:
bash
prefect deployment inspect "your-deployment-name"
Remember that Cloud Run has specific resource constraints:
- CPU must be 1, 2, or 4 vCPUs
- Memory limits depend on CPU configuration:
- 1 vCPU: up to 4Gi
- 2 vCPUs: up to 8Gi
- 4 vCPUs: up to 32GiRasmus
08/01/2025, 11:42 AMMarvin
08/01/2025, 11:42 AMMarvin
08/01/2025, 11:43 AMcloud-run-template.json
) with the resource configurations:
json
{
"job_configuration": {
"resource_limits": {
"cpu": "2",
"memory": "4Gi"
}
}
}
2. Update your work pool with these settings:
bash
prefect work-pool create "your-cloud-run-pool" \
--type cloud-run \
--base-job-template cloud-run-template.json \
--overwrite
Alternatively, you can set this up in the Prefect UI:
1. Go to the Work Pools page
2. Select your Cloud Run work pool
3. Click "Edit"
4. In the "Base Job Template" section, add the resource configurations
5. Save the changes
After setting this up at the work pool level, you can still override these settings for specific deployments in your prefect.yaml
as shown earlier:
yaml
deployments:
- name: your-deployment-name
work_pool:
name: your-cloud-run-pool
job_variables:
resource_limits:
cpu: "4"
memory: "8Gi"
Important notes:
1. The work pool configuration serves as the default for all deployments using that pool
2. Deployment-specific configurations in prefect.yaml
will override the work pool defaults
3. Make sure your Cloud Run service account has the necessary permissions to create jobs with custom resource configurations
4. Remember Cloud Run's resource limits:
- CPU: 1, 2, or 4 vCPUs
- Memory: Must be appropriate for the CPU configuration (e.g., up to 8Gi for 2 vCPUs)
If you're still seeing issues after making these changes:
1. Verify the work pool configuration is correct using:
bash
prefect work-pool inspect "your-cloud-run-pool"
2. Check the Cloud Run logs for any permission or resource-related errors
3. Ensure your Cloud Run worker is running with the latest configurationRasmus
08/01/2025, 4:00 PMMarvin
08/01/2025, 4:00 PMMarvin
08/01/2025, 4:01 PMyaml
deployments:
- name: your-deployment-name
work_pool:
name: your-cloud-run-pool
job_variables:
cpu: "2" # Specify your desired CPU
memory: "4Gi" # Specify your desired memory
This approach is safer because:
1. It only specifies the resource variables (cpu
and memory
)
2. All other default template variables remain untouched
3. The variables are inserted into the default template's {{ cpu }}
and {{ memory }}
placeholders
You can also set these variables in a deployment using Python:
python
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
# your flow code here
pass
deployment = flow.from_source(
source="your-source",
work_pool_name="your-cloud-run-pool",
job_variables={
"cpu": "2",
"memory": "4Gi"
}
).deploy(name="my-deployment")
Important notes:
1. Valid CPU values for Cloud Run: "1", "2", or "4"
2. Memory values must include units and be appropriate for the CPU:
- 1 CPU: up to 4Gi
- 2 CPU: up to 8Gi
- 4 CPU: up to 32Gi
3. All other configurations (timeouts, service accounts, etc.) will remain at their default values
4. The resource specifications will only apply to this specific deployment
To verify the configuration:
1. Check the deployment in the Prefect UI
2. Look at the "Job Configuration" section to confirm only the resource settings were modified
3. Monitor the Cloud Run jobs to ensure they're running with the specified resources
This approach ensures you're only modifying the resource allocations while keeping all other Cloud Run configurations at their default values.