Skip to main content
Deploy DeerFlow on Kubernetes for production-grade isolation and scalability. The provisioner service dynamically creates sandbox pods for each execution context.

Architecture

How It Works

  1. Backend requests sandbox: POST /api/sandboxes with sandbox_id and thread_id
  2. Provisioner creates Pod: Deploys sandbox container with mounted volumes
  3. Service created: NodePort service exposes pod on dynamic port
  4. Backend accesses sandbox: Direct HTTP access via http://NODE_HOST:{NodePort}
  5. Cleanup: DELETE /api/sandboxes/{sandbox_id} removes pod and service

Prerequisites

Kubernetes Cluster

You need a running Kubernetes cluster. Supported options:
  • Docker Desktop with Kubernetes enabled
  • OrbStack (macOS) with built-in K8s
  • minikube for local development
  • kind for local development
  • k3s for lightweight production
  • Cloud providers: EKS, GKE, AKS

Enable Kubernetes in Docker Desktop

  1. Open Docker Desktop settings
  2. Go to “Kubernetes” tab
  3. Check “Enable Kubernetes”
  4. Click “Apply & Restart”
  5. Wait for Kubernetes to start (green indicator)

Enable Kubernetes in OrbStack

  1. Open OrbStack settings
  2. Go to “Kubernetes” tab
  3. Check “Enable Kubernetes”

Verify Cluster

Configuration

1. Configure Sandbox Mode

Edit config.yaml to enable provisioner mode:

2. Set Environment Variables

Edit docker/docker-compose-dev.yaml to configure provisioner:

3. Set Host Paths

Important: SKILLS_HOST_PATH and THREADS_HOST_PATH must be absolute paths on your host machine:

Provisioner Service

Docker Compose Configuration

The provisioner service is defined in docker/docker-compose-dev.yaml:

Provisioner Dockerfile

From docker/provisioner/Dockerfile:

Deployment

Start with Provisioner

Verify Provisioner

Verify Namespace

Sandbox Pod Configuration

Pod Specification

Each sandbox runs as a Kubernetes Pod with:

Service Specification

Each sandbox gets a NodePort service:

API Reference

Health Check

Response:

Create Sandbox

Response:
Status Values:
  • Pending - Pod is being created
  • Running - Pod is ready
  • Succeeded - Pod completed successfully
  • Failed - Pod failed to start
  • Unknown - Status cannot be determined

Get Sandbox Status

Response:

List Sandboxes

Response:

Delete Sandbox

Response:

Testing

Manual Testing

Integration Testing

Test through the DeerFlow application:
  1. Open http://localhost:2026
  2. Create a new thread
  3. Send a message that requires code execution (e.g., “Create a Python script”)
  4. Monitor pod creation:
  5. Check sandbox logs:

Troubleshooting

Kubeconfig Not Found

Symptom: Kubeconfig not found at /root/.kube/config Solution:

Connection Refused to K8s API

Symptom: Connection refused when connecting to Kubernetes API Solution:
  1. Check kubeconfig server address:
  2. If it’s localhost or 127.0.0.1, set K8S_API_SERVER:
  3. For Docker Desktop, the port is usually 6443
  4. For k3s/OrbStack, check the actual port

Invalid HostPath

Symptom: Unprocessable Entity when creating pod Solution:
  1. Use absolute paths only:
  2. Verify paths exist:

Pod Stuck in ContainerCreating

Symptom: Pod stays in ContainerCreating state Diagnosis:
Common causes:
  • Pulling sandbox image (wait or pre-pull with make docker-init)
  • HostPath volume not accessible
  • Insufficient resources on node
Solution:

Cannot Access Sandbox URL

Symptom: Backend cannot reach http://host.docker.internal:{NodePort} Solution:
  1. Verify service exists:
  2. Test from host:
  3. Check extra_hosts in docker-compose (Linux only):
  4. Verify NODE_HOST environment variable

Production Considerations

Resource Limits

Adjust pod resource limits based on workload:

Persistent Storage

For production, consider using PersistentVolumes instead of HostPath:

Network Policies

Restrict sandbox network access:

Automatic Cleanup

Implement TTL for stale sandboxes:

Monitoring

Integrate with Prometheus:

Next Steps

Production Deployment

Production best practices and optimization

Docker Deployment

Learn about Docker-based deployment

See Also