<@ULVA73B9P> - I am trying to pass custom resource...
# ask-marvin
r
@Marvin - I am trying to pass custom resources for different deployments for flows that runs with a k8s worker in GKE on autopilot mode. I am passing the resources like this:
Copy code
{
  "image": "***",
  "job_configuration": {
    "spec": {
      "template": {
        "spec": {
          "containers": [
            {
              "resources": {
                "limits": {
                  "cpu": "1000m",
                  "memory": "1Gi"
                },
                "requests": {
                  "cpu": "2000m",
                  "memory": "512Mi"
                }
              }
            }
          ]
        }
      }
    }
  }
}
However, when i run a deployment, it seems like it overrides the resources i am trying to specify, these are the parameters which are passed to the pod: resources: limits: ephemeral-storage: 1Gi requests: cpu: 500m ephemeral-storage: 1Gi memory: 2Gi I suspect that these are the standard values from a k8s work pool. Can you help me figure out why my custom resources are overwritten?
m
thought for 42.2 seconds
I can see what's happening here. The issue is related to how resource specifications are being merged in your Kubernetes configuration. Here's how to fix it: 1. The resources are being overwritten because the configuration structure in your JSON isn't being properly merged with the worker's base configuration. In Prefect 3.x, you need to ensure your custom resources are specified in the correct location of the job template. 2. For GKE Autopilot specifically, you should be aware that: - The cluster automatically manages node pools - It enforces certain resource requirements - It may override some specifications with its own defaults Here's the correct way to specify your resources:
Copy code
json
{
  "job_template": {
    "apiVersion": "batch/v1",
    "kind": "Job",
    "spec": {
      "template": {
        "spec": {
          "containers": [
            {
              "name": "prefect",
              "resources": {
                "limits": {
                  "cpu": "1000m",
                  "memory": "1Gi"
                },
                "requests": {
                  "cpu": "2000m",
                  "memory": "512Mi"
                }
              }
            }
          ]
        }
      }
    }
  }
}
Key differences and recommendations: 1. Use the
job_template
key instead of
job_configuration
2. Include the complete API version and kind specifications 3. Make sure to specify the container name as "prefect" 4. For GKE Autopilot, ensure your resource requests and limits fall within the allowed ranges: - CPU requests must be between 0.25 and 28 vCPU - Memory requests must be between 0.5 GB and 256 GB You can apply this configuration in two ways: 1. In the work pool configuration (if you want these resources to apply to all deployments using this work pool) 2. In the deployment configuration (if you want these resources to apply to just this specific deployment) Also, note that GKE Autopilot may add some default values for
ephemeral-storage
. This is normal and you can either specify your own value or let it use the defaults. If you're still seeing your values being overridden after making these changes, you might want to: 1. Check your work pool configuration to ensure there aren't any conflicting default values 2. Verify that your GKE Autopilot cluster's constraints aren't forcing different values 3. Ensure you're applying the configuration at the correct level (work pool vs. deployment) You can find more details about Kubernetes configuration in Prefect in the documentation.
r
@Marvin So if i deploy it using flow.deploy like so: hello.deploy( name= "hello-flow-1", work_pool_name="test-work-pool", image="**", job_variables={ "job_configuration": { "spec": { "template": { "spec": { "containers": [{ "resources": { "requests": { "cpu": "100m", "memory": "512Mi" }, "limits": { "cpu": "1000m", "memory": "1Gi" } } }] } } } } } ) What would it look like?
m
thought for 56.2 seconds
Here's the correct way to specify the resources in your
flow.deploy()
call:
Copy code
python
hello.deploy(
    name="hello-flow-1",
    work_pool_name="test-work-pool",
    image="europe-west3-docker.pkg.dev/infrastructure-464107/infrastructure-464107-docker-dev/hello2:latest1",
    job_variables={
        "job_template": {
            "apiVersion": "batch/v1",
            "kind": "Job",
            "spec": {
                "template": {
                    "spec": {
                        "containers": [{
                            "name": "prefect",  # This is important!
                            "resources": {
                                "requests": {
                                    "cpu": "100m",
                                    "memory": "512Mi"
                                },
                                "limits": {
                                    "cpu": "1000m",
                                    "memory": "1Gi"
                                }
                            }
                        }]
                    }
                }
            }
        }
    }
)
Key changes from your version: 1. Changed
job_configuration
to
job_template
2. Added the required Kubernetes API fields (
apiVersion
and
kind
) 3. Added
name: "prefect"
to the container specification 4. Structured the template as a complete Kubernetes job specification This configuration will properly override the default resources with your specified values. The resources you've specified are: - CPU request: 100m (0.1 CPU cores) - CPU limit: 1000m (1 CPU core) - Memory request: 512Mi - Memory limit: 1Gi These values should work fine with GKE Autopilot as they're within the acceptable ranges. If you need to verify that your resources are being applied correctly, you can: 1. Check the deployment configuration in the Prefect UI after deployment 2. Verify the actual pod specifications in your Kubernetes cluster using:
Copy code
bash
   kubectl get pod <pod-name> -o yaml
Remember that if you need to make these resource specifications the default for all deployments using this work pool, you should instead configure them in the work pool settings rather than specifying them in each
deploy()
call.
thought for 8.9 seconds
r
@Marvin Can you redact the above message to hide the image
m
Here's the correct syntax for your
flow.deploy()
call:
Copy code
python
hello.deploy(
    name="hello-flow-1",
    work_pool_name="test-work-pool",
    image="**",  # your image URL here
    job_variables={
        "job_template": {  # Changed from job_configuration
            "apiVersion": "batch/v1",
            "kind": "Job",
            "spec": {
                "template": {
                    "spec": {
                        "containers": [{
                            "name": "prefect",  # Added required name field
                            "resources": {
                                "requests": {
                                    "cpu": "100m",
                                    "memory": "512Mi"
                                },
                                "limits": {
                                    "cpu": "1000m",
                                    "memory": "1Gi"
                                }
                            }
                        }]
                    }
                }
            }
        }
    }
)
The key changes from your version are: 1. Changed
job_configuration
to
job_template
2. Added
apiVersion
and
kind
fields 3. Added the required
name: "prefect"
to the container spec These changes will ensure that your resource specifications are properly applied to the Kubernetes pods when they run. The resources you've specified (100m CPU request, 1000m CPU limit, 512Mi memory request, and 1Gi memory limit) will be used instead of the work pool defaults. If you're still seeing the resources being overridden after making these changes, you might want to check your work pool configuration in the Prefect UI to ensure there aren't any conflicting settings there.
thought for 5.7 seconds
Here's the
flow.deploy()
call with the image redacted:
Copy code
python
hello.deploy(
    name="hello-flow-1",
    work_pool_name="test-work-pool",
    image="***",  # redacted image URL
    job_variables={
        "job_template": {  # Changed from job_configuration
            "apiVersion": "batch/v1",
            "kind": "Job",
            "spec": {
                "template": {
                    "spec": {
                        "containers": [{
                            "name": "prefect",  # Added required name field
                            "resources": {
                                "requests": {
                                    "cpu": "100m",
                                    "memory": "512Mi"
                                },
                                "limits": {
                                    "cpu": "1000m",
                                    "memory": "1Gi"
                                }
                            }
                        }]
                    }
                }
            }
        }
    }
)
The key changes from your version are: 1. Changed
job_configuration
to
job_template
2. Added
apiVersion
and
kind
fields 3. Added the required
name: "prefect"
to the container spec These changes will ensure that your resource specifications are properly applied to the Kubernetes pods when they run. The resources you've specified (100m CPU request, 1000m CPU limit, 512Mi memory request, and 1Gi memory limit) will be used instead of the work pool defaults. If you're still seeing the resources being overridden after making these changes, you might want to check your work pool configuration in the Prefect UI to ensure there aren't any conflicting settings there.
r
@Marvin - Can you delete the message where it is in plain text?
m
thought for 5.2 seconds
I understand you want me to delete a previous message that contained sensitive information. Unfortunately, I don't have the ability to delete or edit previous messages in our conversation - that's something only you or the platform administrators can do. What I can suggest for the future: 1. Be careful not to share sensitive information like image URLs, credentials, or internal paths 2. Use placeholder text like
***
or
<redacted>
when sharing code examples 3. If sensitive information is accidentally shared, you should contact your platform administrator to have it removed Would you like to continue discussing the Kubernetes resource configuration with properly redacted information?
r
@Marvin - how can i get in touch with an administrator?
m
thought for 5.2 seconds
Since this appears to be happening on GitHub Discussions or a similar platform, you should: 1. Look for a "Report" or "Flag" button near the message containing sensitive information 2. If you can't find that, go to GitHub's support: - Visit https://support.github.com - Click "Contact Support" - Explain the situation, including: - The URL of the conversation - Which message contains sensitive information - Why it needs to be removed (security/privacy concerns) Alternatively, if this is happening in a different environment or platform, you should: 1. Check the platform's documentation for contact information 2. Look for a "Help" or "Support" section 3. Search for terms like "report content" or "contact administrator" Without knowing which platform you're using specifically, I can't give more detailed instructions. Could you clarify where this conversation is taking place so I can provide more specific guidance?
r
@Marvin - I am trying to add memory and cpu to my job template for my k8s work pool, can you confirm if this is correct: { "variables": { "type": "object", "properties": { "env": { "type": "object", "title": "Environment Variables", "description": "Environment variables to set when starting a flow run.", "additionalProperties": { "anyOf": [ { "type": "string" }, { "type": "null" } ] } }, "name": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Name", "default": "prefect-worker", "description": "Name given to infrastructure created by a worker." }, "image": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Image", "default": "prefecthq/prefect:3-latest", "examples": [ "docker.io/prefecthq/prefect:3-latest" ], "description": "The image reference of a container image to use for created jobs. If not set, the latest Prefect image will be used." }, "labels": { "type": "object", "title": "Labels", "description": "Labels applied to infrastructure created by a worker.", "additionalProperties": { "type": "string" } }, "command": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Command", "description": "The command to use when starting a flow run. In most cases, this should be left blank and the command will be automatically generated by the worker." }, "namespace": { "type": "string", "title": "Namespace", "default": "prefect", "description": "The Kubernetes namespace to create jobs within." }, "cpu_request": { "type": "string", "title": "CPU Request", "default": "1000m", "description": "The CPU allocation to request for this pod." }, "backoff_limit": { "type": "integer", "title": "Backoff Limit", "default": 0, "minimum": 0, "description": "The number of times Kubernetes will retry a job after pod eviction. If set to 0, Prefect will reschedule the flow run when the pod is evicted." }, "stream_output": { "type": "boolean", "title": "Stream Output", "default": true, "description": "If set, output will be streamed from the job to local standard output." }, "cluster_config": { "anyOf": [ { "$ref": "#/definitions/KubernetesClusterConfig" }, { "type": "null" } ], "description": "The Kubernetes cluster config to use for job creation." }, "memory_request": { "type": "string", "title": "Memory Request", "default": "3Gi", "description": "The Memory allocation to request for this pod." }, "finished_job_ttl": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "title": "Finished Job TTL", "default": 60, "description": "The number of seconds to retain jobs after completion. If set, finished jobs will be cleaned up by Kubernetes after the given delay. If not set, jobs will be retained indefinitely." }, "image_pull_policy": { "enum": [ "IfNotPresent", "Always", "Never" ], "type": "string", "title": "Image Pull Policy", "default": "Always", "description": "The Kubernetes image pull policy to use for job containers." }, "service_account_name": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Service Account Name", "description": "The Kubernetes service account to use for job creation." }, "job_watch_timeout_seconds": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "title": "Job Watch Timeout Seconds", "description": "Number of seconds to wait for each event emitted by a job before timing out. If not set, the worker will wait for each event indefinitely." }, "pod_watch_timeout_seconds": { "type": "integer", "title": "Pod Watch Timeout Seconds", "default": 300, "description": "Number of seconds to watch for pod creation before timing out." } }, "definitions": { "KubernetesClusterConfig": { "type": "object", "title": "KubernetesClusterConfig", "required": [ "config", "context_name" ], "properties": { "config": { "type": "object", "title": "Config", "description": "The entire contents of a kubectl config file.", "additionalProperties": true }, "context_name": { "type": "string", "title": "Context Name", "description": "The name of the kubectl context to use." } }, "description": "Stores configuration for interaction with Kubernetes clusters.\n\nSee
from_file
for creation.", "secret_fields": [], "block_type_slug": "kubernetes-cluster-config", "block_schema_references": {} } }, "description": "Default variables for the Kubernetes worker.\n\nThe schema for this class is used to populate the
variables
section of the default\nbase job template." }, "job_configuration": { "env": "{{ env }}", "name": "{{ name }}", "labels": "{{ labels }}", "command": "{{ command }}", "namespace": "{{ namespace }}", "job_manifest": { "kind": "Job", "spec": { "template": { "spec": { "containers": [ { "env": "{{ env }}", "args": "{{ command }}", "name": "prefect-job", "image": "{{ image }}", "resources": { "requests": { "cpu": "{{ cpu_request }}", "memory": "{{ memory_request }}" } }, "imagePullPolicy": "{{ image_pull_policy }}" } ], "completions": 1, "parallelism": 1, "restartPolicy": "Never", "serviceAccountName": "{{ service_account_name }}" } }, "backoffLimit": "{{ backoff_limit }}", "ttlSecondsAfterFinished": "{{ finished_job_ttl }}" }, "metadata": { "labels": "{{ labels }}", "namespace": "{{ namespace }}", "generateName": "{{ name }}-" }, "apiVersion": "batch/v1" }, "stream_output": "{{ stream_output }}", "cluster_config": "{{ cluster_config }}", "job_watch_timeout_seconds": "{{ job_watch_timeout_seconds }}", "pod_watch_timeout_seconds": "{{ pod_watch_timeout_seconds }}" } }
m
Your message was too long, here's your message at the allowed limit: - I am trying to add memory and cpu to my job template for my k8s work pool can you confirm if this is correct { variables { type object properties { env { type object title Environment Variables description Environment variables to set when starting a flow run additionalProperties { anyOf [ { type string } { type null } ] } } name { anyOf [ { type string } { type null } ] title Name default prefect-worker description Name given to infrastructure created by a worker } image { anyOf [ { type string } { type null } ] title Image default prefecthq/prefect 3-latest examples [ <http //docker io/prefecthq/prefect 3-latest|docker io/prefecthq/prefect 3-latest> ] description The image reference of a container image to use for created jobs If not set the latest Prefect image will be used } labels { type object title Labels description Labels applied to infrastructure created by a worker additionalProperties { type string } } command { anyOf [ { type string } { type null } ] title Command description The command to use when starting a flow run In most cases this should be left blank and the command will be automatically generated by the worker } namespace { type string title Namespace default prefect description The Kubernetes namespace to create jobs within } cpu_request { type string title CPU Request default 1000m description The CPU allocation to request for this pod } backoff_limit { type integer title Backoff Limit default 0 minimum 0 description The number of times Kubernetes will retry a job after pod eviction If set to 0 Prefect will reschedule the flow run when the pod is evicted } stream_output { type boolean title Stream Output default true description If set output will be streamed from the job to local standard output } cluster_config { anyOf [ { $ref #/definitions/KubernetesClusterConfig } { type null } ] description The Kubernetes cluster config to use for job creation } memory_request { type string title Memory Request default 3Gi description The Memory allocation to request for this pod } finished_job_ttl { anyOf [ { type integer } { type null } ] title Finished Job TTL default 60 description The number of seconds to retain jobs after completion If set finished jobs will be cleaned up by Kubernetes after the given delay If not set jobs will be retained indefinitely } image_pull_policy { enum [ IfNotPresent Always Never ] type string title Image Pull Policy default Always description The Kubernetes image pull policy to use for job containers } service_account_name { anyOf [ { type string } { type null } ] title Service Account Name description The Kubernetes service account to use for job creation } job_watch_timeout_seconds { anyOf [ { type integer } { type null } ] title Job Watch Timeout Seconds description Number of seconds to wait for each event emitted by a job before timing out If not set the worker will wait for