Hi everyone, I'm running Prefect in a Kubernetes e...
# ask-community
m
Hi everyone, I'm running Prefect in a Kubernetes environment using the official Helm chart. I am using
selfHostedServer
All deployments share a common
jobTemplate
. Some deployments are more resource-intensive than others. Is there a way to define different
resources.requests/limits
per deployment, without duplicating the entire job template? Thanks!
a
Yes, it is possible to customize different request limits per deployment by adding variables to the base job template. There's an incomplete example hidden in the docs here. I'm realizing that we don't have good docs for this, so let me know if you run into issues and I can help!
b
@Melek Alan are you using
prefect.yaml
to define your deployments?
FWIW, YAML supports "merge keys" which allow you to override key/value pairs. You can pair this with a definitions block in your
prefect.yaml
file. https://docs.prefect.io/v3/how-to-guides/deployments/prefect-yaml#reuse-configuration-across-deployments
Copy code
definitions:
  test: &test
    foo: bar
    bar: baz

deployments:
- name: one
  value: *test
- name: two
  value:
    <<: *test
    foo: not_bar
This would output:
Copy code
deployments:
- name: one
  value:
    foo: bar
    bar: baz
- name: two
  value:
    foo: not_bar
    bar: baz
Note the special
<<: *
syntax which allows you to override a specific setting within that block. You could apply something similar to your
prefect.yaml
file to override deployment-specifc job resource limits.
m
Hey @Brendan Dalpe, @alex We are not using
prefect.yaml
to define deployments. I’ve added the
resources
snippet to our base job template, and all Prefect jobs use it without any issues. The problem is with one specific deployment: it requires higher CPU and memory requests. I’ve added the updated
job variables
configuration in the deployment configuration, and I can see it correctly when I edit the deployment in the UI. However, when the job actually runs, the pod still uses the CPU and memory values from the base job template instead of the deployment configuration. I tried a few things, including removing the
resources
snippet from the base job template, but I still don’t see the deployment-specific configuration applied at runtime. Example snippet from the base job template:
Copy code
"
spec": {
  "containers": [
    {
      "env": "{{ env }}",
      "args": "{{ command }}",
      "name": "prefect-job",
      "image": "{{ image }}",
      "imagePullPolicy": "{{ image_pull_policy }}",
      "resources": {
        "requests": {
          "cpu": "100m",
          "memory": "256Mi"
        }
      }
    }
  ]
}
b
k8s-work-pool-base-config-with-limits.json
@Melek Alan ok, I understand what's going on now. You'll need to modify the Work Pool Base Job template to make this work correctly. I've included an example above. You can set the defaults in your work pool base config. The schema makes 4 new options available for CPU and Memory requests/limits. This will allow you to then override the config on a per-deployment basis and have the correct values passed to your Job/Pod configs.
To edit the Work Pool config JSON schema, go to your work pool, click on the three dots in the top right corner of the screen. Then click edit from the dropdown list. Click the Advanced tab under the Base Job Template section on the edit page.
m
Thanks @Brendan Dalpe much appreciated. That solution worked for me.
🙌 1