Deploying agents to the Flyte sandbox#
After you have finished testing an agent locally, you can deploy your agent to the Flyte sandbox.
Here’s a step by step guide to deploying your agent image to the Flyte sandbox.
Start the Flyte sandbox:
flytectl demo start
Build an agent image: You can go to here to see the Dockerfile we use in flytekit python. Take Databricks agent as an example:
FROM python:3.9-slim-bookworm
RUN apt-get update && apt-get install build-essential git -y
RUN pip install prometheus-client grpcio-health-checking
RUN pip install --no-cache-dir -U flytekit \
git+https://github.com/flyteorg/flytekit.git@<gitsha>#subdirectory=plugins/flytekit-spark \
&& apt-get clean autoclean \
&& apt-get autoremove --yes \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ \
&& :
CMD pyflyte serve agent --port 8000
docker buildx build -t localhost:30000/flyteagent:example -f Dockerfile.agent . --load
docker push localhost:30000/flyteagent:example
Deploy your agent image to the Kubernetes cluster:
kubectl edit deployment flyteagent -n flyte
Search for the image
key and change its value to your agent image:
image: localhost:30000/flyteagent:example
Set up your secrets: Let’s take Databricks agent as an example:
SECRET_VALUE=$(echo -n "<DATABRICKS_TOKEN>" | base64) && \
kubectl patch secret flyteagent -n flyte --patch "{\"data\":{\"flyte_databricks_access_token\":\"$SECRET_VALUE\"}}"
Note
Please ensure two things:
The secret name consists only of lowercase English letters.
The secret value is encoded in Base64.
Restart development:
kubectl rollout restart deployment flyteagent -n flyte
Test your agent remotely in the Flyte sandbox:
pyflyte run --remote agent_workflow.py agent_task
Note
You must build an image that includes the plugin for the task and specify its config with the --image
flag when running pyflyte run
or in an ImageSpec definition in your workflow file.