Pooyan
11/11/2023, 10:53 PMMarvin
11/11/2023, 10:53 PMKubernetesJob infrastructure to execute flow runs in a Kubernetes Job. Here are some requirements for `KubernetesJob`:
- kubectl must be available.
- You must configure remote Storage. Local storage is not supported for Kubernetes.
- The ephemeral Prefect API won't work with Docker and Kubernetes. You must have a Prefect server or Prefect Cloud API endpoint set in your agent's configuration.
You can verify your Prefect worker deployment by running kubectl get pods -n prefect. You should see the Prefect worker pod running. The worker will now be able to communicate with Prefect Cloud and execute your Prefect flows.
For more detailed information, you can refer to these documents:
- KubernetesJob
- Verify Deployment
Please note that the versions of the documents might have changed, so it's always a good idea to check the latest documentation.Nate
11/11/2023, 11:09 PMarn::....::/image:tag as the image field on your k8s work poolPooyan
11/11/2023, 11:22 PMNate
11/11/2023, 11:27 PMprefect.yaml to define deployments, prefect deploy via CLI to create them (recommended for situations like yours where youll be dynamically allocating infra with k8s)
⦠example yaml where I can deploy with prefect deploy -n prefect-github-digest or prefect deploy --all
⢠Flow.deploy if you want to define / create deployments in python (docs)
either way you go, you can invoke the eventual deployment via REST api directly, cli with prefect deployment run <name> or run_deployment from the sdkPooyan
11/11/2023, 11:48 PMrun_deployment and override parameters to run an async flow. Is it possible to invoke multiple concurrent flows with different sets of params?Nate
11/11/2023, 11:48 PMNate
11/11/2023, 11:50 PMasyncio.gather the async subflows directly and they'll run concurrently on the main thread of the parentPooyan
11/11/2023, 11:55 PMPooyan
11/11/2023, 11:55 PMNate
11/11/2023, 11:56 PMNate
11/11/2023, 11:57 PMPooyan
11/12/2023, 12:22 AMinfrastructure_must_have_capabilities method here . If I do under work pool's base template does that mean I have to create a work pool upon runtime as well? Probably not but would you refer me to the work pool base where this should be overriden? Looking at Deployment interface here , work pool name is the only reference I get. So does that mean I should expect each workpool to support a specific type of infra?Nate
11/12/2023, 12:39 AM.deploy would be easiest
you shouldnt need to change the work pool's actual base template for each one, you can just pass job_variables to each .deploy to customize the pool's base template for that deployment with something like
from prefect import flow
@flow
def whatever():
...
job_manifests = {"small": {... dict version of some k8s manifest ...}, "big": {...}}
if __name__ == "__main__":
for name, manifest in job_manifests.items():
whatever.deploy(
name=f"{name}-deployment",
work_pool_name="my-k8s-pool",
job_variables={"job_manifest": manifest}
image="repo/whatever:tag",
push=False
)Pooyan
11/12/2023, 12:41 AMNate
11/12/2023, 12:42 AM