Hi all, I am trying to deploy a flow into a Kuber...
# prefect-cloud
a
Hi all, I am trying to deploy a flow into a Kubernetes Worker pool using the function https://docs.prefect.io/latest/api-ref/prefect/flows/#prefect.flows.Flow.deploy Is it possible to defined the CPU/memory requests and limits that will be assigned to the Kubernetes job using the job_variables argument ? If not how can I specify the CPU and memory assigned to jobs deployed via worker pool please ?
@Nate I know you answered a lot of messages related to prefect.flows.Flow.deploy do you know if this is possible please ?
n
hi @Marvin please find the docs on overriding job variables and link / summarize
m
It appears my search has turned up some useful details regarding overriding job variables in Prefect. Here’s a summary, along with links to the original sources for further reading: ### Summary - Job Variables Overview: Job variables are infrastructure-related values configurable on a work pool. Useful example: setting environment variables. You can override these on a per-deployment basis either using
prefect.yaml
or
.deploy()
method. - Overriding Job Variables in prefect.yaml: You can define job variables within your
prefect.yaml
file under the
job_variables
section. Here is an example:
Copy code
yaml
  deployments:
  - name: demo-deployment
    entrypoint: demo_project/demo_flow.py:some_work
    work_pool:
      name: local
    job_variables:
      env:
        EXECUTION_ENVIRONMENT: staging
        MY_NOT_SO_SECRET_CONFIG: plumbus
    schedule: null
Deploy the flow with these variables using:
Copy code
bash
  prefect deploy -n demo-deployment
- Issues and Considerations: - Deep vs Shallow Merge: Issues raised on GitHub suggest that job variables should use a deep merge rather than a shallow merge of dictionaries. - Multiple Definitions: There's some confusion about precedence when environment variables are defined in multiple places (e.g.,
prefect.yaml
vs. work pool config). - Character Length and Special Characters: There are known issues with character length and names containing invalid characters for Azure Container Instances. ### Useful Links - Overriding Job Variables Guide - GitHub Issues discussing nuances and bugs: - Job variables should use a deep merge rather than shallow merge of dictionaries - Invalid names being generated for Azure Container Instance runs Should you need more details or specifics from the docs or issues, feel free to ask!
n
.deploy() should take a
job_variables
dict
a
thank you very much for your replies @Nate @Marvin @Marvin those bug reposts you found are not related to my question. To clarify: How can I use the job_variables to adjust the cpu / memory available to the kubernetes pod running the prefect flow please ? I know job_variables is a dict and I know it can be used to adjust environmental variables. Kubernetes pods are deployed with a specifric cpu and memory available to them defined by limits.cpu, limits.memory, requests.cpu and requests.memory . Can I adjust those please ?
hi @Marvin is is possible to adjust the cpu / memory available to the kubernetes pod via the argument job_variables submitted to prefect.flows.Flow.deploy ? / summarize
m
Yes, it is possible to adjust the CPU and memory available to a Kubernetes pod via the
job_variables
argument when using the
.deploy()
method in Prefect. Here is a summary of how you can do this: ### Example Usage You can specify job variables, including resource configurations such as CPU and memory, within your
prefect.yaml
file or directly in your
.deploy()
method. #### Using
prefect.yaml
Copy code
yaml
deployments:
- name: demo-deployment
  entrypoint: demo_project/demo_flow.py:some_work
  work_pool:
    name: local
  job_variables:
    kubernetes:
      cpu: "500m"
      memory: "512Mi"
  schedule: null
Deploy with:
Copy code
bash
prefect deploy -n demo-deployment
#### Using
.deploy()
method If you're deploying directly from code, you can pass
job_variables
as a dictionary:
Copy code
python
from prefect import flow

@flow
def my_flow():
    # Your flow code
    pass

if __name__ == "__main__":
    my_flow.deploy(
        name="demo-deployment",
        work_pool_name="local",
        job_variables={
            "kubernetes": {
                "cpu": "500m",
                "memory": "512Mi"
            }
        }
    )
### Helpful Links - Overriding Job Variables Guide This guide details how you can override job variables and includes examples for setting various configuration options, including CPU and memory for Kubernetes. If you have further questions or need additional specifics, feel free to ask!
n
hi @Adam Ivansky - marvin's response is not quite right but its almost right you need to edit your base job template so that
cpu
and
memory
are added to the variables section you can find this in the advanced tab of your work pool in the UI that way you can specify
cpu
/
memory
whatever other value as a job variable
a
@Nate thank you for clarifying that Can I adjust the base job template when calling prefect.flows.Flow.deploy please ? Is there a key in job_variables that I can submit to do that ? I am looking for a way to do this programmatically How would I add CPU / MEMORY adjustment into this call please ?
Copy code
prefect_flow.from_source(
        source=RemoteStorage(
            url=bucket_path,
        ),
        entrypoint="flow.py:entrypoint",
    ).deploy(
        name=name,
        job_variables=job_variables,
        description=description,
        tags=tags,
        schedule=schedule,
        build=False,
        push=False,
        image=os.getenv("IMAGE_URL"),
        work_pool_name="work-pool-1",
        parameters=parameters,
    )