<@ULVA73B9P> I am trying to launch a kubernetes jo...
# ask-marvin
p
@Marvin I am trying to launch a kubernetes job from prefect. I do have a kubernetes worker set up on the cloud and an image stored on ECR. Wondering what the best python class and strategy is in general.
m
Based on the information I found, you can use the
KubernetesJob
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.
n
just heads up, workers have superseded agents, so the second link is what you want you'll put your
arn::....::/image:tag
as the
image
field on your k8s work pool
p
I already have a worker running. Mostly thinking about job creation , deployment and running the flow via python api
n
nice! there's two main paths for deployment definition / creation •
prefect.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 sdk
šŸ‘šŸ» 1
p
Thanks. So if I need to programatically run multiple concurrent flows from a deployment. The best strategy is to have prefect.yaml file and deploy it via cli which makes sense since it doesnt happen often. Then I need to use
run_deployment
and override parameters to run an async flow. Is it possible to invoke multiple concurrent flows with different sets of params?
n
something like this?
well the linked example i just shared is if you need independent infra (pods here) for the children flows you wanna distribute / run if you dont need independent infra then you can just
asyncio.gather
the async subflows directly and they'll run concurrently on the main thread of the parent
šŸ‘šŸ» 1
p
Yeah I need independent pods since I may have different infra requirements.
How should I override infra requirements for each flow?
you can override job variables from your k8s work pool's base template at the deployment level, not yet at the individual flow run level, which means each unique set of job variables will need its own deployment at this time
p
I see. Then it makes sense to deploy at runtime. I see this
infrastructure_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?
n
> Then it makes sense to deploy at runtime this makes sense to me > work pool base where this should be overriden? visually, you can check it out in the advanced tab of your work pools Base Job Template section. there's also this so if you're gonna create deployments more dynamically like this, maybe
.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
Copy code
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
       )
p
Thanks. You are better than Marvin
n
sure thing! and lol, i would hope so, not ready to superseded by my ai child šŸ˜‚
🌟 1