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.

  1. Start the Flyte sandbox:

flytectl demo start
  1. 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
  1. 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
  1. 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:

  1. The secret name consists only of lowercase English letters.

  2. The secret value is encoded in Base64.

  1. Restart development:

kubectl rollout restart deployment flyteagent -n flyte
  1. 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.