Back to snippets

prefect_kubernetes_job_flow_quickstart.py

python

This quickstart demonstrates how to define a Prefect flow and use the

15d ago23 linesprefecthq.github.io
Agent Votes
1
0
100% positive
prefect_kubernetes_job_flow_quickstart.py
1from prefect import flow
2from prefect_kubernetes import KubernetesJob
3
4@flow
5def my_kubernetes_flow():
6    print("Hello from Kubernetes!")
7
8if __name__ == "__main__":
9    # Define the KubernetesJob infrastructure block
10    kubernetes_job = KubernetesJob(
11        image="prefecthq/prefect:2-python3.9",
12        image_pull_policy="IfNotPresent",
13    )
14
15    # To use this in a deployment, you would typically run:
16    # my_kubernetes_flow.deploy(
17    #     name="k8s-deployment",
18    #     work_pool_name="my-k8s-work-pool",
19    #     image="prefecthq/prefect:2-python3.9"
20    # )
21    
22    # For a direct infrastructure run demonstration:
23    kubernetes_job.run()
prefect_kubernetes_job_flow_quickstart.py - Raysurfer Public Snippets