Is there a preferred way of installing requirement...
# prefect-kubernetes
j
Is there a preferred way of installing requirements for a flow onto a kubernetes worker deployed using helm?
1
j
I believe the preferred method would be to build a custom docker image that has your requirements installed on it
z
An alternative is to set the
EXTRA_PIP_PACKAGES
variable but that increase the startup time of each job.
j
If I went the custom docker image route how would that affect us using the helm chart for deploying? The extra_pip_packages does sound a little easier since we typically don’t have that many extras to install for our flows, but the increase in startup time for the jobs does sound not ideal
z
Do you need the requirements to be available for the flow run pod or the worker pod?
j
The only pod that is deployed in our K8 cluster is the worker pod
Unless there should also be a flow run pod? I just used the helm chart to deploy and when I go to view the pods running in our namespace I only see the worker pod
z
The worker creates a job / pod for each flow run
1
Anyway you probably want the requirements in the flow run pod which means you can just set the image on your flow’s deployment — no need for changing anything with the helm chart.
j
Gotcha. Okay that makes sense! Thank you so much
@Zanie I tried to use the
EXTRA_PIP_PACKAGES
argument in my deployment. I am using terraform with helm_release to deploy, and when I passed in the argument
worker.extraEnvVars.EXTRA_PIP_PACKAGES
Copy code
│ Error: YAML parse error on prefect-worker/templates/deployment.yaml: error converting YAML to JSON: yaml: line 67: did not find expected '-' indicator
I looked around and saw that I could also do
env.EXTRA_PIP_PACKAGES
instead but it looks like the helm chart doesn’t support that if I am looking in the right place?
j
you’ll need to specify it with something like this:
Copy code
worker.extraEnvVars[0].name = EXTRA_PIP_PACKAGES
worker.extraEnvVars[0].value = PACKAGE_NAME
see here
j
Ahhhhhh gotcha! So in theory I could do
Copy code
set {
    name  = "worker.extraEnvVars[0]"
    value = "prefect-slack==0.1.2"
  }
j
hm I’m not sure that would work — I think this would work:
Copy code
resource "helm_release" "prefect" {
  repository = "<https://prefecthq.github.io/prefect-helm>"
  chart      = "prefect-worker"
  version    = "2023.05.25"
  name       = "prefect-worker"
  values = [<<-EOF
  worker:
    extraEnvVars: 
      - name: EXTRA_PIP_PACKAGES
        value: prefect-slack==0.1.2
  EOF
  ]
}
👀 1
j
That deployed, but I have noticed another issue. The worker-pod definitely has that environment variable now, but when it goes to create flow run pods those do not have the same environment variable (EXTRA_PIP_PACKAGES don’t exist in the created flow run pod). So I don’t believe it is installing that package on flow execution
j
oh - if you want it for your flow pods you’ll need to set that env var in the infra_overrides section of either your work-pool or your deployment.
under your work pool definition
or under your deployments.yaml
Copy code
deployments:  
  - name: Deployment Name
    version: null
    tags: []
    description: null
    schedule: {}
    flow_name: null
    entrypoint: path/to/flow.py:flow
    parameters: {}
    work_pool:
      name: kubernetes
      job_variables:
        env:
          EXTRA_PIP_PACKAGES: prefect-slack==0.1.2
🙌 1
j
Yes that was it! Thank you so much
Apologies for all my questions, my brain is still working between Prefect 1.0 and 2.0 🙂 but I think I can take the rest for here 🚀
j
haha no worries at all! happy to help
🙌 1