Deploy with Docker and Kubernetes
In shortGenerate a Dockerfile, docker-compose.yml and Kubernetes manifest with 10xgraph build, then ship them with a production environment checklist.
- 10 min read
- 8 sections
- Updated
- v1.0.0
- Markdown
10xgraph build generates a production-ready Dockerfile and .dockerignore for your agent, and with flags also a docker-compose.yml and a k8s.yaml manifest. The images run Gunicorn with Uvicorn workers in MODE=production. This guide covers building, configuring, and shipping your deployment with a release checklist.
The image and manifests implement the behavior described in scaling and reliability. Draining runs on shutdown is covered in Graceful shutdown.
-
Generate the deployment files
Run it in the project root, next to
10xgraph.json.Terminal 10xgraph build --docker-compose --k8s -
Pin your dependencies
The Dockerfile installs from the first of
requirements.txt,requirements/requirements.txt,requirements/base.txtorrequirements/production.txtthat exists. With none of those, it readspyproject.tomldependencies. With neither, it installs only10xgraph-api, so your own packages would be missing. -
Build and run
Terminal docker compose up --build -
Check health
Terminal curl http://localhost:8000/ping
Which flags does build take?
| Flag | Default | Effect |
|---|---|---|
--output, -o |
Dockerfile |
Dockerfile path |
--force, -f |
off | Overwrite existing files |
--python-version |
3.13 |
Base image python:<version>-slim |
--port, -p |
8000 |
Port to expose |
--docker-compose / --no-docker-compose |
off | Also write docker-compose.yml and omit CMD from the Dockerfile |
--k8s / --no-k8s |
off | Also write k8s.yaml |
--service-name |
10xgraph-api |
Service name in compose and Kubernetes files |
--worker / --no-worker |
asked | Include a background worker. Needs a non-memory worker key in 10xgraph.json |
--scheduler / --no-scheduler |
off | Include the scheduler. Needs the worker |
Without --force, build stops if the Dockerfile exists. It keeps an existing .dockerignore but appends any secret patterns it lacks (keys, certificates, cloud credential files), and errors on an existing docker-compose.yml or k8s.yaml.
Questions and background jobs
At an interactive terminal, build asks up to four questions and skips any that a flag answers or that do not apply:
- Where will you deploy? Docker Compose, Kubernetes or Dockerfile only. Skipped when you pass
--docker-composeor--k8s. - Run a background worker? Default yes. Asked only when
10xgraph.jsonhas aworkerkey whose broker is notmemory, and the target is Compose or Kubernetes. - Run the scheduler? Default no. Asked only after a yes to the worker.
- Overwrite existing files? Asked only when files exist and you did not pass
--force. No stops without writing.
Pass --yes or --non-interactive to skip the questions. Without a terminal, the worker is included when the config has a non-memory worker key, and the scheduler only with --scheduler. --worker without a worker key, or with the memory broker, is an error, and so is --scheduler without a worker. With the memory broker no worker is generated, because tasks run inside the API, and build prints a note. build warns when your dependencies do not list 10xgraph-api with the extra for the broker (jobs, jobs-rabbitmq or jobs-kafka).
What files does it generate?
- your-project/
- 10xgraph.json
- Dockerfilepython:3.13-slim, non-root user (uid 10001), healthcheck on /ping
- .dockerignoreexcludes .env, keys and credential files, caches, venvs, .git, eval_reports, tests, evals and agent skill folders
- docker-compose.ymlwith
--docker-compose, plusworkerandschedulerservices when you include them - k8s.yamlwith
--k8s, plus worker and scheduler Deployments when you include them
The Dockerfile sets MODE=production and WEB_CONCURRENCY=2, installs gunicorn and uvicorn, removes the CLI-only files from the installed package, copies your project, drops to the non-root user appuser (fixed uid and gid 10001, set as USER 10001:10001 so Kubernetes can verify it is not root), and defines a HEALTHCHECK that calls /ping. Its CMD runs tenxgraph_api.src.app.main:app under Gunicorn with the TenxGraphUvicornWorker class (tenxgraph_api.src.app.uvicorn_worker.TenxGraphUvicornWorker), --graceful-timeout 600, --timeout 660 and --no-control-socket (the gunicorn control server would write /app/.gunicorn, and the root filesystem is read-only). The worker marks the app as draining on SIGTERM, so /health/ready answers 503 while open runs finish. TENXGRAPH_GRACEFUL_SHUTDOWN_SECONDS (default 540) sets how long uvicorn waits for open responses; see Graceful shutdown.
Does the image ship the CLI and the config editor?
No. 10xgraph-api is one package with two halves: the API server, and the CLI you use on your machine (init, build, eval, the 10xgraph config browser editor, project templates and the bundled agent skill). Seeing CLI code and HTML/JS in the package can look like extra attack surface on a production server. It is not, for two reasons.
The server never touches the CLI half. It imports one CLI file, tenxgraph_api/cli/constants.py, for the version string. No route serves the editor’s HTML or JS, and the editor itself only runs when you type 10xgraph config. Even then it listens on 127.0.0.1 and needs a random per-session token.
The generated image removes it anyway. Right after installing dependencies, the Dockerfile deletes the templates and the config editor from the installed package:
# Strip CLI-only assets the server never loads: project scaffolds, the bundled
# agent skill, and the local config editor (HTML/JS). Only the server code and
# its dependencies stay in the image.
RUN python -I -c "import importlib.util, pathlib, shutil; spec = importlib.util.find_spec('tenxgraph_api'); cli = pathlib.Path(spec.origin).parent / 'cli' if spec and spec.origin else None; [shutil.rmtree(cli / d, ignore_errors=True) for d in ('templates', 'config_editor') if cli]"The CLI’s small Python modules stay, so 10xgraph version and 10xgraph audit still work inside a running container for debugging.
The generated .dockerignore does the same for your project: tests/, evals/ and installed skill folders (.claude/, .agents/, .github/) are not copied into the image, along with .env files, private keys and certificates (*.pem, *.key, *.p12), cloud credential files (service_account*.json, credentials*.json, .aws/), caches and virtual environments.
You can check a built image yourself:
docker build -t my-agent .
docker run --rm my-agent python -c "import pathlib, tenxgraph_api; print(sorted(p.name for p in (pathlib.Path(tenxgraph_api.__file__).parent / 'cli').iterdir()))"The list has no templates or config_editor entry.
How do I run it in Docker Compose or Kubernetes?
Docker Compose
The compose file defines one service with build: ., the production environment, the same Gunicorn command, stop_grace_period: 660s and restart: unless-stopped. It reads secrets and ORIGINS/ALLOWED_HOST from .env through env_file, so they never enter the image. Copy .env.example to .env and fill it in first.
If you included the worker, the file also has a worker service, and with the scheduler a scheduler service. Both are built from the same image as the API, read the same .env, use the same lockdown settings and publish no ports. They run 10xgraph worker and 10xgraph scheduler in the image. The worker waits up to 600 seconds for running tasks on shutdown. The scheduler carries a comment: run exactly one, and remove the service if you have no schedules. See Background tasks.
docker compose up --build -dThe port is published on 127.0.0.1:8000 only: the server speaks plain HTTP, so a TLS reverse proxy (Caddy, nginx or a cloud load balancer) on the same host is what faces the internet. If the proxy runs on another host, remove the 127.0.0.1: prefix and firewall the port to that host.
The container runs with read_only: true, cap_drop: [ALL] and no-new-privileges. Only /tmp (a tmpfs) and /app/uploads (the named volume uploads) are writable. If your graph writes elsewhere, for example a SQLite checkpointer file, mount a volume at that path.
Kubernetes
k8s.yaml holds a Deployment with 2 replicas and a Service on port 80 that targets your container port.
If you included the worker, the file also has a <service>-worker Deployment, and with the scheduler a <service>-scheduler Deployment. They have no Service and no HTTP probes, and use the same security context and Secret as the API. The scheduler runs one replica with strategy: Recreate, so a rollout never runs two.
docker build -t registry.example.com/my-agent:1.0 .
docker push registry.example.com/my-agent:1.0
kubectl create secret generic my-agent-secrets \
--from-literal=JWT_SECRET_KEY=... --from-literal=GOOGLE_API_KEY=... \
--from-literal=ORIGINS=https://your-frontend.example.com \
--from-literal=ALLOWED_HOST=your-app.example.com
# edit the image in k8s.yaml, then:
kubectl apply -f k8s.yamlThe settings that protect running agents:
| Setting | Value | Why |
|---|---|---|
terminationGracePeriodSeconds |
675 | Longer than the 600 second Gunicorn drain plus the 15 second preStop sleep, which runs inside the same period |
preStop |
sleep 15 |
Lets the load balancer stop sending new requests first |
readinessProbe |
/health/ready, every 10s |
Removes the pod from rotation |
livenessProbe |
/ping, every 30s, 5 failures |
Slack enough that a busy worker is not restarted mid-run |
| Resources | request 500m CPU and 512Mi, limit 2 CPU and 2Gi | Starting point, tune for your load |
The settings that lock the pod down:
| Setting | Value |
|---|---|
automountServiceAccountToken |
false: the server never calls the Kubernetes API |
Pod securityContext |
runAsNonRoot, uid/gid/fsGroup 10001, seccompProfile: RuntimeDefault |
Container securityContext |
readOnlyRootFilesystem, allowPrivilegeEscalation: false, all capabilities dropped |
| Volumes | emptyDir at /tmp (Gunicorn heartbeats) and /app/uploads (local media) |
| Secrets | envFrom the Secret <service>-secrets; the pod does not start until it exists |
The manifest sets MODE. ORIGINS and ALLOWED_HOST come from the Secret too, with everything secret; a value in the manifest would override the Secret. Create it with --from-literal or a secret manager, not --from-env-file .env: kubectl keeps the quotes from a .env file as part of each value.
Choose your deployment path
Before building, decide whether you need persistence, multiple instances, and public access. This flowchart guides the decision:
flowchart TD
A[Do you need public or team access?] -->|No| B[Stay local with 10xgraph dev]
A -->|Yes| C[Do you need persistence?]
C -->|No| D[Single-instance simple deployment]
C -->|Yes| E[Shared durable checkpointer]
E --> F[Do you need multiple replicas?]
F -->|No| G[Single durable instance]
F -->|Yes| H[Load balanced multi-instance deployment]
For local development, 10xgraph dev is sufficient. For shared or production use:
- Persistence required: Set a durable checkpointer (for example
PgCheckpointer), by passing it tograph.compile(checkpointer=...)in your graph code (thecheckpointerkey in10xgraph.jsonis not read). In-memory checkpointing loses all threads on restart. - Multiple instances: Use a shared durable checkpointer and a shared store (if using long-term memory). Each instance must access the same database backend.
- Shared state across instances: Set
"cache_store": {"type": "redis"}so the API’s cache store is shared. It holds the run locks, caps, idempotency state, token revocation and rate-limit counters. The in-memory store counts per process and is not shared.
Production environment settings
The generated files set MODE=production. Add the following at runtime:
| Variable | Set to | Why |
|---|---|---|
ORIGINS |
Comma-separated list of your frontend origins | k8s.yaml reads it from the Secret; compose reads it from .env. A wildcard * stops startup in production unless STRICT_PRODUCTION_CHECKS=false, and is always refused when CORS_ALLOW_CREDENTIALS is true |
ALLOWED_HOST |
Your hostnames | Comma-separated. k8s.yaml reads it from the Secret; compose reads it from .env. A wildcard * stops startup in production unless STRICT_PRODUCTION_CHECKS=false |
JWT_SECRET_KEY |
32+ bytes, from a secret manager | Required if auth is jwt. See Add JWT authentication |
JWT_ALGORITHM |
HS256 or your choice |
Required with jwt |
REDIS_URL |
Your Redis connection URL | Optional. The server uses it for a cache_store of type redis that has no url. Without such a cache_store the cache store is in-memory and per process |
WEB_CONCURRENCY |
Workers per container | Default 2. Tune for your CPU and load |
For durable persistence and distributed deployments, also configure:
- A
PgCheckpointeror equivalent (never rely on in-memory checkpointing in production). - A
BaseStoresubclass if you use long-term memory. - Role-based access control, if owner-only threads are not enough: add
rolesto theauthobject.
Full reference is in the configuration and environment pages.
Before release: verification checklist
Before deploying to production, run these checks to catch configuration issues early:
-
Health endpoint
Terminal curl http://127.0.0.1:8000/ping -
Graph schema
Terminal curl http://127.0.0.1:8000/v1/graph -
Auth is enforced (if enabled)
- Without credentials: auth-protected routes return 401
- With valid credentials: requests succeed
-
CORS is restricted
- Requests from allowed origins succeed
- Requests from disallowed origins are rejected
-
Documentation is hidden (if intentional)
- In
MODE=productionthe server turns/docsand/redocsoff unless you setDOCS_PATHorREDOCS_PATHexplicitly (they should return 404) - Check that neither variable is set in your deployment
- In
-
Persistence survives restart
- Invoke an agent without a
thread_idand save the one the server returns indata.meta.thread_id - Restart the server or container
- Fetch the same thread: messages and state should be intact
- Invoke an agent without a
-
Multiple instances sync (if deployed with replicas)
- Invoke an agent on instance A, get a thread_id
- Fetch that thread on instance B: state should be identical
- This confirms the checkpointer and store backends are shared
Record the results before going live. If any check fails, fix the configuration and repeat.
Frequently asked questions
- Why does the generated config wait so long to shut down?
- An agent run can take minutes, and Gunicorn's default 30 second graceful timeout would kill runs mid-flight on every rolling deploy. The generated files use a 600 second graceful timeout, a 660 second worker timeout, a 660 second Compose stop grace period and a 675 second Kubernetes grace period.
- Can I change the image name in k8s.yaml?
- Yes. The manifest uses the placeholder image registry.example.com/<service>:1.0.0. Build and push your own image, then set the image field to its version tag or digest before applying.
- Does build read my 10xgraph.json?
- No. It looks for a requirements file or pyproject.toml, and the container reads 10xgraph.json at runtime, so your code and config must be copied into the image.
- The 10xgraph-api package contains CLI code, project templates and a browser config editor. Is that a security risk in production?
- No. The server never imports or serves any of it, and the generated Dockerfile deletes the templates and the config editor from the image after installing dependencies. The only CLI file the server loads is a small constants module.