Introduction

Product Version

This document applies to ZStack API Router preview.

Intended Audience

This document describes environment preparation, installation, deployment, and post-deployment validation. It is intended for:

  • Deployment and operations engineers.
  • Platform administrators.
  • Technical support engineers.
  • Delivery engineers responsible for model gateway deployment.

Deployment Overview

ZStack API Router can run as a standalone API gateway or as part of a ZStack AIOS or LobsterPool inference path. The core service is zr-server. PostgreSQL is used as the runtime database. Database migration must be applied before startup. The optional worker component synchronizes models and probes channel health.

Deployment Modes

Deployment ModeScenarioDescription
Single-node deploymentTrial, demo, small environmentPostgreSQL and gateway services run on one node or one Compose environment.
Production deploymentProduction workloadsPostgreSQL runs independently. Nginx, Ingress, or load balancer provides the entry point.
Offline deploymentAir-gapped or controlled data centerUses offline image packages, environment templates, and startup scripts.
Compatibility deploymentLobsterPool or legacy gateway grayscale replacementUses /openai/v1/* compatibility entry points.

Components

ComponentRequiredDescription
zr-serverYesMain service for control plane, data plane, health checks, and metrics.
zr-migrateYesApplies PostgreSQL schema migration before service startup.
zr-workerOptionalSynchronizes channel models and probes channel health.
PostgreSQLYesStores configuration, key hashes, organizations, logs, audit records, and quotas.
Nginx or IngressRecommended for productionProvides HTTPS, domain entry, grayscale release, and access control.
PrometheusRecommended for productionScrapes /metrics.

Environment Preparation

Supported Operating Systems

Operating SystemDescription
Rocky Linux 8 or compatible distributionsRecommended for production.
CentOS 7 or compatible distributionsSuitable for existing environments after Docker and system libraries are verified.
Ubuntu Server 20.04 or laterSuitable for development, testing, and production.
macOSRecommended only for local development and validation.

Component Versions

ComponentRequirementDescription
PostgreSQL14 or later, 16 recommendedRuntime database.
Docker20.10 or laterRequired for Docker deployment.
Docker Composev2.0 or laterRequired for Compose deployment.
Nginx1.20 or laterOptional for production ingress, HTTPS, and grayscale release.
systemdStandard Linux distribution versionRequired for binary process management.

Hardware Requirements

EnvironmentCPUMemoryDiskDescription
Single-node trial2 cores4 GB50 GBBasic validation and light traffic.
Small production4 cores8 GB100 GBDedicated PostgreSQL disk recommended.
Medium production8 cores16 GB200 GBDedicated PostgreSQL, log directory, and metrics collection recommended.
High-concurrency streaming16 cores or more32 GB or morePlan by log retentionPlan file descriptors, connection pools, and ingress carefully.

Network and Port Requirements

Port or DirectionRequirement
3080Default zr-server port. Configurable with ZR_BIND_ADDR.
PostgreSQL portGateway nodes must reach the database.
Upstream model servicesGateway nodes must reach model providers or private inference services.
80, 443Required when exposing HTTP or HTTPS through Nginx or Ingress.
DNSRequired for upstream model services, public domain, and database hostname.
NTPRecommended to keep logs and authentication timestamps accurate.

TLS and Domain Requirements

Prepare the following for production:

  • Public or internal domain, for example api-router.example.com.
  • Valid TLS certificate.
  • DNS record pointing to Nginx, Ingress, or load balancer.
  • Path routing for /api/zr/*, /v1/*, /openai/v1/*, /healthz, /readyz, and /metrics.

Permission and Directory Requirements

ItemRequirement
Runtime userUse a dedicated system user in production.
Configuration fileEnvironment files contain secrets and should use permission 600.
Log directoryThe runtime user must have write permission.
Diagnostic file directoryUpstream failure diagnostic file directory must be persistent and access-controlled.
systemdOperators need permission to start, stop, and view service logs.
DockerThe deployment user needs Docker operation permission.

Pre-deployment Checks

Complete these checks before installation:

CheckMethod
Database connectivityConnect to PostgreSQL with psql.
Port availabilityCheck whether 3080 or the planned port is occupied.
Disk capacityVerify database, log, and diagnostic file directories.
Upstream networkAccess model provider URLs from the gateway node.
Ingress proxyConfirm path routing for data plane and control plane.
TLS certificateVerify certificate validity and domain match.
Metrics collectionConfirm Prometheus can access /metrics.
Backup strategyConfirm PostgreSQL backup and restore procedures.
Security settingsEnsure real secrets are not stored in documents, default scripts, or public logs.

Single-node Docker Compose Deployment

Scenario

Use this mode for trial, demo, feature validation, and small environments.

Prerequisites

  • Docker and Docker Compose are installed.
  • The current user can run Docker commands.
  • Local port 3080 and the configured PostgreSQL port are available.

Procedure

  1. Enter the deployment directory:
cd zstack-router
  1. Review the environment template:
sed -n '1,120p' .env.example
  1. Start services:
docker compose up --build -d
  1. Check service status:
docker compose ps
  1. View logs:
docker compose logs -f zr-server
docker compose logs -f zr-worker

Verification

curl -fsS http://127.0.0.1:3080/healthz
curl -fsS http://127.0.0.1:3080/readyz
curl -fsS http://127.0.0.1:3080/api/zr/openapi.json

Notes

  • The Compose default configuration is for validation and should not be used directly for large production deployments.
  • Use an independent PostgreSQL instance and configure backups for production.
  • If only APIs are required, the console static directory can remain disabled.

Production Deployment

Scenario

Use this mode for production workloads with independent PostgreSQL, zr-server, optional zr-worker, and an ingress proxy.

Prerequisites

  • Production PostgreSQL is ready.
  • Backup strategy is prepared.
  • Domain, TLS certificate, and ingress proxy are ready.
  • Dedicated runtime user and deployment directories are prepared.

Prepare Database

create user zstack_router with password 'CHANGE_ME';
create database zstack_router owner zstack_router;

Verify connectivity:

psql 'postgres://zstack_router:CHANGE_ME@{DB_HOST}:5432/zstack_router' -c 'select now();'

Configure Environment Variables

Create /etc/zstack-router/zstack-router.env:

ZR_DATABASE_URL=postgres://zstack_router:CHANGE_ME@{DB_HOST}:5432/zstack_router
ZR_BIND_ADDR=0.0.0.0:3080
ZR_PROVIDER_MODE=openai
ZR_CLOUD_TOKEN=Bearer {CLOUD_TOKEN}
ZR_DISCOVERY_TOKEN=Bearer {DISCOVERY_TOKEN}
ZR_CONSOLE_DIST_DIR=/usr/share/zstack-router-console
ZR_PROVIDER_FAILURE_DUMP_DIR=/var/lib/zstack-router/provider-failures

Set permissions:

chmod 600 /etc/zstack-router/zstack-router.env
chown zstack-router:zstack-router /etc/zstack-router/zstack-router.env

Apply Database Migration

export $(grep -v '^#' /etc/zstack-router/zstack-router.env | xargs)
zr-migrate

Start Services

Start zr-server with systemd or a container platform. Start zr-worker if model synchronization and channel health probing are required.

Configure Ingress Proxy

Nginx or Ingress should forward:

PathTarget
/api/zr/zr-server
/v1/zr-server
/openai/v1/zr-server
/feedbackzr-server
/healthz, /readyzzr-server
/metricszr-server, access restricted to monitoring systems.
/ai-gatewayzr-server, only when the console is enabled.

Disable response buffering for streaming APIs.

Verification

  • Access /healthz and /readyz from the entry domain name.
  • Use a test API Key to call /v1/chat/completions.
  • Open the console and confirm that Channel, Model, Route Policy, Usage Log, and Audit Log pages can be accessed.
  • Confirm that metrics are collected by the monitoring system.

Offline Deployment

Scenario

Use this mode in air-gapped environments or data centers that cannot access public image registries.

Prerequisites

  • Offline deployment package is available.
  • Docker and Docker Compose are installed, or prerequisites are included in the package.
  • PostgreSQL is prepared or the package-provided database configuration is accepted.

Procedure

  1. Upload the offline package to the target server.
  2. Extract the package to the deployment directory.
  3. Review env.example, docker-compose.yml, and load-and-run.sh.
  4. Create and edit .env.
  5. Load images and start services:
bash load-and-run.sh
  1. Run health checks.

Notes

  • Ensure all deployment files come from the same package version.
  • Offline environments still require database backups.
  • Include Docker and Compose prerequisites when packaging if the target environment does not provide them.

Post-deployment Validation

CheckExpected Result
zr-migrateDatabase migration succeeds.
zr-serverListens on the target port.
zr-workerRuns without continuous failures if enabled.
/healthzReturns success.
/readyzReturns ready.
/metricsCan be scraped by monitoring.
ConsoleCan be opened and logged in if enabled.
Data planeAPI Key can call the target model.
Usage LogA new usage record is created after a request.
Audit LogAdministrative operations create audit records.

Troubleshooting

/readyz Is Abnormal

Possible causes:

  • ZR_DATABASE_URL is incorrect.
  • PostgreSQL is unreachable.
  • zr-migrate has not been executed or failed.

Verify database connectivity, review zr-server logs, and rerun zr-migrate.

Data Plane Cannot Reach Upstream Models

Possible causes:

  • Upstream URL is unreachable.
  • Credential is incorrect.
  • SSRF policy blocks the URL.
  • Channel has not synchronized models.

Check network access, channel configuration, model synchronization, Usage Log records, and upstream failure diagnostic files.

Streaming Responses Are Unstable

Possible causes:

  • Nginx or Ingress buffers streaming responses.
  • Process file descriptor limit is too low.
  • PostgreSQL connection pool is insufficient.

Disable buffering for streaming paths, raise LimitNOFILE or container nofile, and tune the database pool.

Appendix: Common Operations Commands

curl -fsS http://127.0.0.1:3080/healthz
curl -fsS http://127.0.0.1:3080/readyz
curl -fsS http://127.0.0.1:3080/metrics

Query recent usage:

select endpoint, status, upstream_status, count(*) as requests,
       max(created_at) as last_seen
from zr_usage_logs
where created_at >= now() - interval '30 minutes'
group by endpoint, status, upstream_status
order by last_seen desc;