Skip to content

K8sStatefulSet

K8sStatefulSet creates a Kubernetes StatefulSet in the target cluster. StatefulSets manage stateful pods with stable, persistent network identities and ordered deployment, scaling, and termination.

Property Type Required Description
cluster KubernetesCluster | string Target cluster
namespace K8sNamespace | string Namespace to deploy into
dependsOn string[] Explicit dependency ordering
image string Container image (e.g., 'postgres:16')
replicas number Desired pod count (defaults to 1)
serviceName K8sService | string Headless service governing network identity
ports { containerPort: number; name?: string; protocol?: string }[] Container ports to expose
env { name: string; value?: string; valueFrom?: Record }[] Environment variables
volumeClaimTemplates { name: string; accessModes: string[]; size: string; storageClassName?: string }[] Template for per-pod PVCs
spec Record<string, unknown> Raw pod template spec overrides
const dbHeadless = new K8sService({
name: 'db-svc',
cluster: myCluster,
serviceType: 'ClusterIP',
clusterIP: 'None',
ports: [{ port: 5432, name: 'postgres' }],
})
const postgres = new K8sStatefulSet({
name: 'postgres',
cluster: myCluster,
namespace: myNamespace,
image: 'postgres:16',
replicas: 3,
serviceName: dbHeadless,
ports: [{ containerPort: 5432, name: 'postgres' }],
env: [
{ name: 'POSTGRES_PASSWORD', valueFrom: { secretKeyRef: { name: 'pg-pass', key: 'password' } } },
],
volumeClaimTemplates: [
{ name: 'data', accessModes: ['ReadWriteOnce'], size: '100Gi', storageClassName: 'ssd' },
],
})
Provider Supported
Kubernetes
Hetzner
DigitalOcean
AWS
GCP