How to use custom image for each flow deployment i...
# prefect-kubernetes
s
How to use custom image for each flow deployment in kubernetes worker pool I have prefect k8s work-pool setup with one worker, and I have prefect.yaml setup for deployment. I don't want prefect to build the docker image for me, but I wish to specify each deployment having its own image, is this possible? Currently I configure the image section of the k8s worker But this makes all workflow run using this image. Is there a way to adjust my deployment so that different deployment use different images?
Copy code
name: flows
prefect-version: 2.14.2

# pull section allows you to provide instructions for cloning this project in remote locations
pull:
- prefect.deployments.steps.set_working_directory:
    directory: /opt/prefect

# the definitions section allows you to define reusable components for your deployments
definitions:
  tags: &common_tags
    - "sat"
  work_pool: &common_work_pool
    name: "k8s-pool"
    job_variables:
      image: "{{ build-image.image }}"

# the deployments section allows you to provide configuration for deploying flows
deployments:
- name: "flow"
  schedule: null
  entrypoint: "src/sat/sub_flows/flow.py:flow"
  work_pool: *common_work_pool
I am aware that there is an option with
flow.serve
, I am able to create a deployment for each flow as well, but then I don't know how to roll out new deployment in this way without interrupting a running flow. With flow.serve running in a deployment, when I need to update a flow, I need to delete the deployment and re-deploy that deploymnet, this makes the running flow on original deployment fail. This is way I eneded up switch to use prefect.yaml to specify deployment, and each deployment runs in its own k8s job (I do like this design, much easier and clearer resource separation), but the issue is now I do not know how to set different flow image for each flow in the same k8s worker pool
turns out there is .deploy, so nice! I am guessing through prefect.yaml it can be overwrite by job_variables
Copy code
if __name__ == "__main__":
    firstrun_flow.deploy( # type: ignore
        name="example",
        image="custom image here",
        build: False,
        push: False,
    )
👍 1
k
Yep, if you're using
prefect.yaml
and
prefect deploy
you don't want your image built, you can leave the
build
and
push
steps empty and set the
image
for each deployment under
job_variables
.