@crossdelta/infrastructure

中文文档
0.19.0发布于 2026/10/25MITTypeScriptESM + CJS近 30 天下载 4405

npm version License: MIT

原始使用文档
文档目录10 节
  1. When to use this
  2. When NOT to use this
  3. Install
  4. What's included
  5. Quick Start
  6. Service Config
  7. Shared Cluster (Multi-Stack)
  8. generate-env CLI
  9. Limitations
  10. License

@crossdelta/infrastructure

npm version License: MIT

Opinionated Pulumi library for deploying microservices to DigitalOcean Kubernetes (DOKS). You describe each service as a typed config object, the package generates Deployments, Services, Ingress, Secrets, health probes, and rolling update strategies.

Built for teams running TypeScript microservices on DOKS with NATS JetStream, GHCR, and Pulumi. If that's your stack, this saves real boilerplate. If not, you're probably better off with plain Pulumi or Helm.

When to use this

  • You deploy multiple TypeScript services to a DigitalOcean Kubernetes cluster
  • You use Pulumi (not Terraform, not Helm-only) for infrastructure
  • You want one config object per service instead of ~150 lines of K8s resource declarations
  • You need NATS JetStream, NGINX Ingress, cert-manager, or Caddy as a reverse proxy

When NOT to use this

  • AWS/GCP/Azure: Only DOKS is implemented. EKS/AKS/GKE are not supported.
  • Terraform or plain Helm: This is Pulumi-only.
  • Non-opinionated setups: The package makes choices for you (Helm chart versions, deployment strategies, DO-specific annotations). If you need full control, use Pulumi directly.
  • Single-service projects: The overhead isn't worth it for one service.

Install

npm install @crossdelta/infrastructure @pulumi/pulumi @pulumi/kubernetes
# For DOKS cluster creation:
npm install @pulumi/digitalocean
# For NATS stream deployment (optional):
npm install @crossdelta/cloudevents

What's included

ModuleWhat it does
ClustercreateDOKSCluster(), createVPC(), createK8sProviderFromKubeconfig()
WorkloadsdeployK8sService(), deployK8sServices(), createNamespace(), createImagePullSecret()
NGINX IngressdeployNginxIngress() via Helm (chart v4.11.3)
cert-managerdeployCertManager() via Helm (chart v1.16.2)
NATSdeployNats() via Helm (chart v1.2.6), buildNatsUrl()
CaddydeployCaddy(), generateCaddyfile() for reverse proxy with on-demand TLS
StreamscollectStreamDefinitions(), deployStreams(), materializeStreams() (NATS JetStream)
Service DiscoverydiscoverServiceConfigs() auto-discovers configs from infra/services/*.ts
Local DevgenerateComposeYaml(), k3d cluster scripts
CLIgenerate-env generates .env.local from Pulumi config + service discovery

Quick Start

One index.ts that provisions a cluster, runtime components, and all services:

import {
  createDOKSCluster,
  createVPC,
  createNamespace,
  deployRuntime,
  deployK8sServices,
  discoverServiceConfigs,
} from '@crossdelta/infrastructure'

const vpc = createVPC({ name: 'my-vpc', region: 'fra1' })
const { provider } = createDOKSCluster({
  name: 'my-cluster',
  vpcUuid: vpc.id,
  nodePool: { name: 'default', size: 's-4vcpu-8gb', nodeCount: 1 },
})
createNamespace(provider, 'my-namespace')

const runtime = deployRuntime(provider, 'my-namespace', {
  nats: { enabled: true, config: { replicas: 1, jetstream: { enabled: true } } },
  ingress: { enabled: true },
  certManager: { enabled: true, config: { email: '[email protected]' } },
})

const configs = discoverServiceConfigs('services')
deployK8sServices(provider, 'my-namespace', configs)

Service Config

Each file in infra/services/ exports one config object. The package derives all K8s resources from it:

import { ports, type K8sServiceConfig } from '@crossdelta/infrastructure'

const config: K8sServiceConfig = {
  name: 'my-service',
  ports: ports().http(4000).public().build(),
  healthCheck: { httpPath: '/health' },
  ingress: { path: '/api', host: 'example.com' },
  env: { DATABASE_URL: dbUrl },
  secrets: { API_KEY: apiKey },
  resources: {
    requests: { cpu: '50m', memory: '64Mi' },
    limits: { cpu: '200m', memory: '256Mi' },
  },
}

export default config

See K8sServiceConfig for all fields: replicas, volumes, strategy, containerEnv, labels, annotations, serviceType, etc.

From replicas: 2 upward a service also gets a topology spread constraint (one pod per node, ScheduleAnyway) and a PodDisruptionBudget (maxUnavailable: 1). Below two replicas neither is created, because a PodDisruptionBudget on a single replica would block every node drain. Set highAvailability: false to opt a multi-replica service out, for example when its pods share a ReadWriteOnce volume.

Shared Cluster (Multi-Stack)

Pin DigitalOcean resource names with clusterName/vpcName to share a cluster across Pulumi stacks:

// Stage stack owns the cluster
const { provider, kubeconfig } = createDOKSCluster({
  name: 'my-cluster',
  clusterName: 'my-cluster',
  vpcUuid: vpc.id,
  nodePool: { name: 'default', size: 's-4vcpu-8gb', nodeCount: 1 },
})
export const clusterKubeconfig = kubeconfig

// Production stack references stage
const stageStack = new StackReference('org/project/stage')
const provider = createK8sProviderFromKubeconfig(
  'production',
  stageStack.getOutput('clusterKubeconfig'),
)

generate-env CLI

Generates .env.local from Pulumi secrets and discovered service configs:

npx generate-env              # defaults to stage stack
npx generate-env --stack=production
npx generate-env --no-pulumi  # skip Pulumi, only service discovery

Limitations

  • DOKS only. No other cloud provider is implemented.
  • Helm chart versions are pinned. NGINX v4.11.3, cert-manager v1.16.2, NATS v1.2.6. No override option yet.
  • Service discovery assumes a convention: infra/services/*.ts files with export default config.
  • @crossdelta/cloudevents is a hard dependency even if you don't use NATS streams https://github.com/orderboss/platform/issues/TBD.
  • Caddy deployment uses Recreate strategy (RWO PVC incompatible with rolling updates).

License

MIT © crossdelta

版本与发布记录

@crossdelta/infrastructure 共发布 92 个版本,首次发布于 2025/12/01;过去 12 个月发布了 92 个版本。

版本发布日期距今
0.19.0latest2026/10/2516 天前
0.18.12026/10/1724 天前
0.18.02026/10/1526 天前
0.17.02026/10/1527 天前
0.16.02026/09/221 个月前
0.15.42026/09/131 个月前

关于 @crossdelta/infrastructure 的常见问题

如何安装 @crossdelta/infrastructure?

在项目目录运行 npm install @crossdelta/infrastructure,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 generate-env,可以用 npx generate-env 直接运行。

@crossdelta/infrastructure 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crossdelta/infrastructure 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@crossdelta/infrastructure 可以商用吗?

@crossdelta/infrastructure 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@crossdelta/infrastructure 的下载量有多少?

根据 npm 官方下载统计,@crossdelta/infrastructure 在 2026/10/11 – 2026/11/09 这 30 天内被下载 4,405 次,日均约 147 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crossdelta/infrastructure 还在维护吗?

最新版本 0.19.0 发布于 2026/10/25(16 天前);至今共发布 92 个版本,其中过去 12 个月发布了 92 个;首次发布于 2025/12/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。