Skip to content

Kubernetes Factories ​

Factory functions for creating Kubernetes native resources with full type safety.

Quick Example ​

typescript
import { Deployment, Service } from 'typekro/simple';

const deploy = Deployment({
  id: 'app',
  name: 'my-app',
  image: 'nginx:latest',
  replicas: 3
});

const svc = Service({
  id: 'svc',
  name: 'my-app-svc',
  selector: { app: 'my-app' },
  ports: [{ port: 80 }]
});

Import Patterns ​

See Import Patterns for complete import documentation.

typescript
// Recommended: direct imports from subpath
import { Deployment, Service } from 'typekro/simple';

// Alternative: namespace import
import { simple } from 'typekro';
const deploy = simple.Deployment({ id: 'app', name: 'app', image: 'nginx' });

Categories ​

Workloads ​

FactoryDescription
DeploymentStateless application deployments
StatefulSetStateful applications with stable identities
DaemonSetRun pods on every node
JobBatch processing
CronJobScheduled tasks

Networking ​

FactoryDescription
ServiceExpose applications
IngressHTTP routing
NetworkPolicyPod network isolation

Configuration ​

FactoryDescription
ConfigMapConfiguration data
SecretSensitive data

Core Resources ​

For resources not in simple factories, use core factories:

typescript
import { namespace, pod } from 'typekro';

const ns = namespace({
  metadata: { name: 'my-namespace' }
});

const debugPod = pod({
  metadata: { name: 'debug', namespace: 'default' },
  spec: {
    containers: [{ name: 'debug', image: 'busybox', command: ['sleep', '3600'] }]
  }
});

Storage ​

FactoryDescription
PvcPersistentVolumeClaim
PersistentVolumeStorage volumes

Autoscaling ​

FactoryDescription
HpaHorizontal Pod Autoscaler

Helm ​

FactoryDescription
HelmChartSimplified Helm chart deployment

The id Parameter ​

Every factory requires an id for cross-resource references:

typescript
import { Deployment, Service } from 'typekro/simple';

const db = Deployment({ id: 'db', name: 'postgres', image: 'postgres' });
const dbService = Service({
  id: 'dbSvc',
  name: 'postgres-svc',
  selector: { app: 'postgres' },
  ports: [{ port: 5432 }]
});

const app = Deployment({
  id: 'app',
  name: 'api',
  image: 'myapi',
  env: {
    DB_HOST: dbService.status.clusterIP  // Cross-reference using id
  }
});

Next Steps ​

Released under the Apache 2.0 License.