ZStack API Router Installation and Deployment Guide

Introduction

Product Version

This document applies to ZStack API Router 1.0.0.

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 Mode Scenario Description
Single-node deployment Trial, demo, small environment PostgreSQL and gateway services run on one node or one Compose environment.
Production deployment Production workloads PostgreSQL runs independently. Nginx, Ingress, or load balancer provides the entry point.
Offline deployment Air-gapped or controlled data center Uses offline image packages, environment templates, and startup scripts.
Compatibility deployment LobsterPool or legacy gateway grayscale replacement Uses /openai/v1/* compatibility entry points.

Components

Component Required Description
zr-server Yes Main service for control plane, data plane, health checks, and metrics.
zr-migrate Yes Applies PostgreSQL schema migration before service startup.
zr-worker Optional Synchronizes channel models and probes channel health.
PostgreSQL Yes Stores configuration, key hashes, organizations, logs, audit records, and quotas.
Nginx or Ingress Recommended for production Provides HTTPS, domain entry, grayscale release, and access control.
Prometheus Recommended for production Scrapes /metrics.

Environment Preparation

Supported Operating Systems

Operating System Description
Rocky Linux 8 or compatible distributions Recommended for production.
CentOS 7 or compatible distributions Suitable for existing environments after Docker and system libraries are verified.
Ubuntu Server 20.04 or later Suitable for development, testing, and production.
macOS Recommended only for local development and validation.

Component Versions

Component Requirement Description
PostgreSQL 14 or later, 16 recommended Runtime database.
Docker 20.10 or later Required for Docker deployment.
Docker Compose v2.0 or later Required for Compose deployment.
Nginx 1.20 or later Optional for production ingress, HTTPS, and grayscale release.
systemd Standard Linux distribution version Required for binary process management.

Hardware Requirements

Environment CPU Memory Disk Description
Single-node trial 2 cores 4 GB 50 GB Basic validation and light traffic.
Small production 4 cores 8 GB 100 GB Dedicated PostgreSQL disk recommended.
Medium production 8 cores 16 GB 200 GB Dedicated PostgreSQL, log directory, and metrics collection recommended.
High-concurrency streaming 16 cores or more 32 GB or more Plan by log retention Plan file descriptors, connection pools, and ingress carefully.

Network and Port Requirements

Port or Direction Requirement
3080 Default zr-server port. Configurable with ZR_BIND_ADDR.
PostgreSQL port Gateway nodes must reach the database.
Upstream model services Gateway nodes must reach model providers or private inference services.
80, 443 Required when exposing HTTP or HTTPS through Nginx or Ingress.
DNS Required for upstream model services, public domain, and database hostname.
NTP Recommended 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

Item Requirement
Runtime user Use a dedicated system user in production.
Configuration file Environment files contain secrets and should use permission 600.
Log directory The runtime user must have write permission.
Diagnostic file directory Upstream failure diagnostic file directory must be persistent and access-controlled.
systemd Operators need permission to start, stop, and view service logs.
Docker The deployment user needs Docker operation permission.

Pre-deployment Checks

Complete these checks before installation:

Check Method
Database connectivity Connect to PostgreSQL with psql.
Port availability Check whether 3080 or the planned port is occupied.
Disk capacity Verify database, log, and diagnostic file directories.
Upstream network Access model provider URLs from the gateway node.
Ingress proxy Confirm path routing for data plane and control plane.
TLS certificate Verify certificate validity and domain match.
Metrics collection Confirm Prometheus can access /metrics.
Backup strategy Confirm PostgreSQL backup and restore procedures.
Security settings Ensure 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
  2. Review the environment template:
    sed -n '1,120p' .env.example
  3. Start services:
    docker compose up --build -d
  4. Check service status:
    docker compose ps
  5. 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:

Path Target
/api/zr/ zr-server
/v1/ zr-server
/openai/v1/ zr-server
/feedback zr-server
/healthz, /readyz zr-server
/metrics zr-server, access restricted to monitoring systems.
/ai-gateway zr-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
  6. 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

Check Expected Result
zr-migrate Database migration succeeds.
zr-server Listens on the target port.
zr-worker Runs without continuous failures if enabled.
/healthz Returns success.
/readyz Returns ready.
/metrics Can be scraped by monitoring.
Console Can be opened and logged in if enabled.
Data plane API Key can call the target model.
Usage Log A new usage record is created after a request.
Audit Log Administrative 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;
Installation and Deployment Guide | ZStack API Router · AIOS | ZStack Resource Center