Learn how to run flows on Kubernetes using containers.
eksctl
.
Node pools can be backed by either EC2 instances or FARGATE.
Choose FARGATE so there’s less to manage.
The following command takes around 15 minutes and must not be interrupted:namespace
field to prefect
prefect
in all commands below.{"EXTRA_PIP_PACKAGES":"my_package"}
.
For example {"EXTRA_PIP_PACKAGES":"pandas==1.2.3"}
installs pandas version 1.2.3.
Alternatively, you can specify package installation in a custom Dockerfile, whichrequirements.txt
file baked in.
Namespace
Set the Kubernetes namespace to create jobs within, such as prefect
. By default, set
to default.
Image
Specify the Docker container image for created jobs.
If not set, the latest Prefect 3 image is used (for example, prefecthq/prefect:3-latest
).
You can override this on each deployment through job_variables
.
Image Pull Policy
Select from the dropdown options to specify when to pull the image.
When using the IfNotPresent
policy, make sure to use unique image tags, orcontainers
item under job_configuration
:values.yaml
file to customize the Prefect worker configuration.
Add the following contents to the file:
values.yaml
file:
flows
, create a file named hello.py
with the following contents:
python hello.py
to verify that it works.
Use the tags
context manager to tag the flow run as local
.
This step is not required, but does add some helpful metadata.
flow.deploy
mechanics or in a
prefect.yaml
definition file.
The prefect.yaml
file currently allows for more customization in terms of push and pull
steps.
To learn about the Python deployment creation method with flow.deploy
see
Workers.
The prefect.yaml
file is used
by the prefect deploy
command to deploy your flows.
As a part of that process it also builds and pushes your image.
Create a new file named prefect.yaml
with the following contents:
hello
flow: default
and arthur
.
By specifying dockerfile: auto
, Prefect automatically creates a dockerfile
that installs any requirements.txt
and copies over the current directory.
You can pass a custom Dockerfile instead with dockerfile: Dockerfile
or
dockerfile: path/to/Dockerfile
.
We are specifically building for the linux/amd64
platform.
This specification is often necessary when images are built on Macs with M series chips
but run on cloud provider instances.
requirements.txt
file:
prefect.yaml
file with a few minor modifications, since it’s not yet
an option with the Python deployment creation method.
Use the run_shell_script
command to grab the SHA and pass it to the tag
parameter of build_docker_image
:
deploy
time.
This example uses a virtual environment to ensure consistency across environments.
prefect.yaml
file to get the image name from the
PREFECT_IMAGE_NAME
environment variable, so set that first:
prefect deploy --all
or deploy them individually by name: prefect deploy -n hello/default
or prefect deploy -n hello/arthur
.