Quickstart
This runs a Prefect server, a worker, and a scheduled flow in one namespace. It takes about five minutes, most of it pulling the Prefect image.
1. Start a Prefect server
apiVersion: prefect.io/v1
kind: PrefectServer
metadata:
name: prefect
spec: {}kubectl apply -f server.yaml
kubectl get prefectserver prefect --watchAn empty spec gives an ephemeral server: its database is SQLite in an
emptyDir, so it loses everything when the pod restarts. Wait for READY to
become true:
NAME VERSION READY
prefect 3.9.4 trueThe operator created a Deployment and a Service, both named prefect, and owns
them:
kubectl get deployment,service -l prefect.io/server=prefect2. Add a work pool and a worker
A work pool is a named queue of flow runs in Prefect. A worker is a process
that polls one work pool and runs what it finds. The process type runs each
flow as a subprocess of the worker, which keeps this example to one pod.
apiVersion: prefect.io/v1
kind: PrefectWorkPool
metadata:
name: process-pool
spec:
type: process
server:
name: prefect
workers: 1kubectl apply -f work-pool.yaml
kubectl get prefectworkpool process-poolNAME TYPE VERSION READY DESIRED WORKERS READY WORKERS
process-pool process 3.9.4 true 1 13. Deploy a flow
A Prefect deployment tells Prefect where a flow’s code is and when to run it.
This one clones a public repository and runs hello from
flows/hello_world.py every minute:
apiVersion: prefect.io/v1
kind: PrefectDeployment
metadata:
name: hello
spec:
server:
name: prefect
workPool:
name: process-pool
deployment:
entrypoint: flows/hello_world.py:hello
pullSteps:
- prefect.deployments.steps.git_clone:
repository: https://github.com/PrefectHQ/examples.git
branch: main
parameters:
name: Kubernetes
schedules:
- slug: every-minute
cron: "* * * * *"kubectl apply -f deployment.yaml
kubectl get prefectdeployment hello -o jsonpath='{.status.conditions[?(@.type=="Synced")]}{"\n"}'Within a minute or two, the worker’s logs show the flow run:
kubectl logs deployment/process-pool -f4. Open the Prefect UI
kubectl port-forward service/prefect 4200:4200Open http://localhost:4200. The deployment hello is under Deployments,
and its runs are under Runs.
Clean up
kubectl delete -f server.yaml -f work-pool.yaml -f deployment.yamlThe command waits while the operator deletes the deployment and the work pool
from Prefect. The PrefectServer stays up until both are gone, and then
Kubernetes deletes it along with its Deployment and Service. See
Deleting a server.
Next steps
- Keep the server’s data: Server storage.
- Run each flow in its own pod: set the work pool’s
typetokubernetes. See Prefect for Kubernetes users. - Use Prefect Cloud instead of an in-cluster server: Connect to Prefect Cloud.