@crossdelta/infrastructure
v0.8.5
Published
[](https://www.npmjs.com/package/@crossdelta/infrastructure) [](https://opensource.org/licenses/MIT)
Downloads
2,333
Readme
@crossdelta/infrastructure
Opinionated Pulumi abstractions for deploying microservices to Kubernetes. Turns per-service config objects into Deployments, Services, Ingress, probes, and secrets.
Installation
npm install @crossdelta/infrastructure @pulumi/pulumi @pulumi/kubernetesUsage
Service config
import { ports, type K8sServiceConfig } from '@crossdelta/infrastructure'
const config: K8sServiceConfig = {
name: 'my-service',
ports: ports().http(4000).public().build(),
replicas: 1,
healthCheck: {
httpPath: '/health',
readinessPath: '/health/ready',
},
ingress: { path: '/api', host: 'example.com' },
env: { DATABASE_URL: dbUrl },
containerEnv: { NODE_OPTIONS: '--max-old-space-size=384' },
secrets: { API_KEY: apiKey },
resources: {
requests: { cpu: '50m', memory: '64Mi' },
limits: { cpu: '200m', memory: '256Mi' },
},
}
export default configDeploy services
import { deployK8sServices, discoverServiceConfigs } from '@crossdelta/infrastructure'
const serviceConfigs = discoverServiceConfigs('services')
deployK8sServices({
provider,
namespace,
serviceConfigs,
env: { NATS_URL: natsUrl },
})Deploy runtime components
import { deployRuntime } from '@crossdelta/infrastructure'
const runtime = deployRuntime(provider, namespace, {
nats: { enabled: true, config: { replicas: 1, jetstream: { enabled: true } } },
ingress: {
enabled: true,
config: {
nginxConfig: {
'proxy-buffer-size': '16k', // Increase for large auth cookies/JWTs
},
},
},
certManager: { enabled: true, config: { email: '[email protected]' } },
})K8sServiceConfig
interface K8sServiceConfig {
name: string
ports: PortConfig
replicas?: number
resources?: {
requests?: { cpu: string; memory: string }
limits?: { cpu: string; memory: string }
}
healthCheck?: {
httpPath: string
readinessPath?: string // Falls back to httpPath
initialDelaySeconds?: number // Default: 10
periodSeconds?: number // Default: 10
failureThreshold?: number // Default: 3
}
ingress?: {
path: string
host?: string
}
env?: Record<string, pulumi.Input<string>>
containerEnv?: Record<string, pulumi.Input<string>>
secrets?: Record<string, pulumi.Input<string>>
image?: string
skip?: boolean
}Fluent Ports API
import { ports } from '@crossdelta/infrastructure'
ports().http(4000).build() // Simple HTTP
ports().http(4000).public().build() // Public (ingress)
ports().grpc(50051).build() // gRPC
ports().http(4000).addHttp(8080, 'metrics').build() // Multiple ports| Method | Description |
|--------|-------------|
| .http(port) | HTTP primary port |
| .grpc(port) | gRPC primary port |
| .primary(port, name?) | Custom primary port |
| .add(port, name?, protocol?) | Additional port |
| .addHttp(port, name?) | Additional HTTP port |
| .addGrpc(port, name?) | Additional gRPC port |
| .public() | Expose via ingress |
| .protocol(type) | Set protocol (TCP, UDP, SCTP) |
| .build() | Build config |
API Reference
| Function | Description |
|----------|-------------|
| deployRuntime(provider, ns, config) | Deploy runtime components |
| discoverServiceConfigs(dir, opts?) | Auto-discover service configs from filesystem |
| deployK8sServices(opts) | Deploy services to cluster |
| createNamespace(provider, name) | Create k8s namespace |
| createImagePullSecret(...) | Create registry pull secret |
| ports() | Fluent port builder |
License
MIT © crossdelta
