<@ULVA73B9P> I've not been keeping up with all the...
# ask-marvin
d
@Marvin I've not been keeping up with all the changes and I'm unsure how to proceed with deploying a flow so it'll use a pre-built container image when triggered by a worker in kubernetes. Can you show an example please? We're using a self-hosted server, but I believe this is covered by having PREFECT_API_URL set at deployment time
m
🔄 Researching your answer... this may take a while 🔧 Using tool:
check_cli_command
📊 Tools used: •
check_cli_command
(7x) •
explore_module_offerings
(3x)
d
@Marvin, did you give up? I've managed to work it out with copliot's help. This is what I've found to work: from prefect import flow @flow def my_flow(): print("hello from ACR image") if name == "__main__": my_flow.deploy( name="my-flow", work_pool_name="my-aks", image="my-acr.azurecr.io/prefectjobs:latest", build=False, # <-- important: disable build push=False, # you're not pushing anything from here # cron="0 * * * *" # optional schedule )
m
âś… thought for 404.2 seconds
Nice! That’s a solid approach for Prefect 3.x when you’ve already built and pushed your image. A couple of quick confirmations and tips: - Your
build=False
and
push=False
are exactly right for “use an existing image.” - Make sure the
image
string is the plain name (e.g., `my-acr.azurecr.io/prefectjobs:latest`). Slack sometimes adds
<...|...>
link formatting — don’t paste that into code. - If your code lives inside the image, this is perfect. If your code lives in a repo instead, consider
Flow.from_source(...).deploy(...)
. Your example (cleaned up for Slack formatting) would be:
Copy code
from prefect import flow

@flow
def my_flow():
    print("hello from ACR image")

if __name__ == "__main__":
    my_flow.deploy(
        name="my-flow",
        work_pool_name="my-aks",
        image="<http://my-acr.azurecr.io/prefectjobs:latest|my-acr.azurecr.io/prefectjobs:latest>",
        build=False,
        push=False,
        # cron="0 * * * *",  # optional
    )
Kubernetes work pool + ACR auth (AKS) tips: - If AKS is attached to your ACR (via Azure RBAC), you may not need an
imagePullSecret
. - Otherwise, add
imagePullSecrets
and (optionally) a
serviceAccountName
to your Kubernetes work pool’s base job template. You can grab Prefect’s default Kubernetes job template, edit it, and update your work pool:
Copy code
prefect work-pool get-default-base-job-template --type kubernetes --file k8s-base.json
# Edit k8s-base.json -> add under job_manifest.spec.template.spec:
# "imagePullSecrets": [{"name": "acr-pull-secret"}],
# "serviceAccountName": "prefect-runner"
prefect work-pool update my-aks --base-job-template k8s-base.json
Docs to keep handy: - Kubernetes work pools and job templates: Prefect 3: Run on Kubernetes - Managing work pools: Prefect 3: Manage work pools If you want, I can draft a minimal
k8s-base.json
with
imagePullSecrets
and a service account for your
my-aks
pool.