Kubernetes.LocalCluster reference
LocalCluster
Section titled “LocalCluster”Source:
packages/kubernetes/src/LocalCluster.ts
A Kubernetes cluster on your machine, for trying Alchemy’s Kubernetes resources and developing against them without a hosted cluster.
LocalCluster runs a kind cluster in Docker
together with a local image registry wired into the cluster’s nodes, so
workloads built from a main Effect program or a context Dockerfile
work the same way they do on a hosted cluster with a registry. Pass the
resource as the cluster of any Kubernetes.* resource.
Requires Docker and the kind CLI on the deploying machine (set
KIND_BIN to use a specific binary). The cluster’s kubeconfig context,
kind-<name>, works with kubectl.
LocalCluster: Creating a Local Cluster
Section titled “LocalCluster: Creating a Local Cluster”const cluster = yield* Kubernetes.LocalCluster("Cluster", { name: "alchemy",});
const web = yield* Kubernetes.Deployment("Web", { cluster, image: "ghcr.io/stefanprodan/podinfo:6.15.0", port: 9898, serviceType: "ClusterIP",});LocalCluster: Effect Programs
Section titled “LocalCluster: Effect Programs”const cluster = yield* Kubernetes.LocalCluster("Cluster", { name: "alchemy",});
const hello = yield* Kubernetes.Job( "Hello", { cluster, main: import.meta.url }, Effect.gen(function* () { return { run: Effect.log("hello from a Job"), }; }),);LocalCluster: Kind Configuration
Section titled “LocalCluster: Kind Configuration”Forward a host port to a NodePort
const cluster = yield* Kubernetes.LocalCluster("Cluster", { name: "alchemy", nodes: [ { role: "control-plane", extraPortMappings: [{ containerPort: 30080, hostPort: 8080 }], }, ],});Forward a NodePort to a free host port
const cluster = yield* Kubernetes.LocalCluster("Cluster", { nodes: [ { role: "control-plane", extraPortMappings: [{ containerPort: 30080, hostPort: 0 }], }, ],});const url = cluster.ports.pipe( Output.map((ports) => { const port = ports.find((p) => p.containerPort === 30080); return `http://localhost:${port?.hostPort}`; }),);LocalCluster: Registry Port
Section titled “LocalCluster: Registry Port”Two local clusters
const blue = yield* Kubernetes.LocalCluster("Blue", { name: "blue" });const green = yield* Kubernetes.LocalCluster("Green", { name: "green", registryPort: 5002,});A registry on a free port
const cluster = yield* Kubernetes.LocalCluster("Cluster", { registryPort: 0 });cluster.registry; // { server: "localhost:<a free port>" }LocalCluster: Looking up an existing cluster
Section titled “LocalCluster: Looking up an existing cluster”LocalCluster.lookup references a kind cluster Alchemy doesn’t manage (applied with
kubectl, Helm or another stack). It is read during plan/deploy, never
applied, updated or deleted.
const cluster = Kubernetes.LocalCluster.lookup({ name: "dev" });yield* Kubernetes.Manifest("Settings", { cluster, manifest });