Guide for testing out KubernetesFlowRunner locally

Install Docker Desktop:

Start a Local Kubernetes Cluster:

In terminal screen #1

prefect kubernetes manifest orion | kubectl apply -f -
kubectl port-forward deployment/orion 4200:4200

In a separate terminal #2 (I like to use the command screen)

prefect work-queue create kubernetes-test  # use output from this
prefect agent start <UUID> # here

In separate terminal #3, copy this script in test.py

from prefect import flow, task
from prefect.deployments import DeploymentSpec
from prefect.flow_runners import KubernetesFlowRunner


@task
def helper():
    print('Hello from Kubernetes task!')


@flow()
def my_kubernetes_flow():

    print('Hello from Kubernetes flow!')
    helper()


DeploymentSpec(
    name="k8s-example",
    flow=my_kubernetes_flow,    
    flow_runner=KubernetesFlowRunner(pod_watch_timeout_seconds=60)
)

Then run this in terminal #3

prefect deployment create test.py
prefect deployment run my-kubernetes-flow/k8s-example
1 Like