Skip to content
betterstack-alchemyUnofficial

Kubernetes

A KubernetesCluster is managed Kubernetes on Better Stack Cloud. Better Stack runs the control plane for you, for free (Better Stack’s Kubernetes docs); the workers come from KubernetesNodePools, and they are ordinary servers, billed at server prices and counted against your server quotas.

us-west-2aavailability zone
k8sKubernetesCluster · control plane
cost
free
out
kubeconfig
workersKubernetesNodePool · AM4 × 2
billed
as servers
  • workersjoin →k8s
The control plane runs on one server Better Stack manages; each node pool adds workers of one server type to it.

A cluster needs no props at all; apiAllowedCidrs limits who can reach its Kubernetes API:

alchemy.run.ts
const cluster = yield* BetterStack.Cloud.KubernetesCluster("k8s", {
// Who may reach the Kubernetes API, such as your office or CI runners.
apiAllowedCidrs: ["203.0.113.0/24"],
});

The deploy blocks until the control plane is running, which can take up to 45 minutes, and fails with WaitFailed when it ends failed or degraded, or WaitTimeout past that budget. name, metadata and apiAllowedCidrs change in place.

A node pool is a group of workers of one server type. Pick at least 4 vCPU and 4 GB: Kubernetes itself takes some of every node.

alchemy.run.ts
const workers = yield* BetterStack.Cloud.KubernetesNodePool("workers", {
kubernetesClusterId: cluster.id,
serverType: "AM4", // at least 4 vCPU and 4 GB per worker
nodeCount: 2,
labels: { tier: "backend" },
taints: [{ key: "dedicated", value: "backend", effect: "NoSchedule" }],
});

nodeCount (0 to 100; scaling down drains each worker first), labels and taints change in place, and the deploy waits until the pool is active again (up to 30 minutes; its workers can still be joining). serverType replaces the pool: that is how you move workers to another type. A cluster has at most 10 node pools and 100 workers.

A deleted pool’s name stays taken until the delete finishes, so a replacement that keeps an explicit name deletes the old pool first and retries its create while the name is still reserved. Leave name out to replace create-before-delete under a fresh generated name.

version is the Kubernetes major.minor, defaulting to the newest; patch releases are applied for you. A higher version upgrades in place, one minor version at a time, after a snapshot of the control plane:

alchemy.run.ts
const version = yield* BetterStack.Cloud.latestKubernetesVersion().pipe(Effect.orDie);
const network = yield* BetterStack.Cloud.Network("private", {
ipPrefix: "10.0.0.0",
ipPrefixLength: 24,
});
const platform = yield* BetterStack.Cloud.KubernetesCluster("platform", {
version, // such as "1.36"; a higher one upgrades in place
podCidr: "10.100.0.0/16",
serviceCidr: "10.101.0.0/16",
networkIds: [network.id],
});

networkIds and firewallIds (at most one firewall, applied to the workers) attach and detach in place. podCidr and serviceCidr (default 10.42.0.0/16 and 10.43.0.0/16), teamId and availabilityZone replace the cluster, which removes its control plane, workers, snapshots and the load balancers its Services created.

Once the control plane is running, the cluster’s attributes carry the API endpoint, the kubeconfig (admin access, Redacted), certificateAuthorityData, and a connection shaped like the one AWS.EKS.Cluster and GCP.Container.Cluster expose:

alchemy.run.ts
const env = {
KUBECONFIG_DATA: cluster.kubeconfig, // Redacted, admin access
};
// cluster.connection: { endpoint, certificateAuthorityData, auth: { kind: "token", token } }
const api = cluster.endpoint;

Reach the API from an address in apiAllowedCidrs. The deploy never rotates the admin credentials on its own: change rotateCredentials to a new value to rotate them once (the previous ones stop working). A rotation done in Better Stack’s console or CLI is read on the next deploy.

A KubernetesScheduledSnapshot snapshots the control plane hourly, daily, weekly or monthly:

alchemy.run.ts
yield* BetterStack.Cloud.KubernetesScheduledSnapshot("daily", {
kubernetesClusterId: cluster.id,
frequency: "daily",
});

A snapshot holds the cluster’s state, not the workers or persistent volume data: use volume snapshots for those. Restoring one rolls the cluster back in place. Snapshots and schedules are removed with the cluster.

Deleting a cluster removes its control plane, workers, control-plane snapshots and the load balancers its Kubernetes Services created, but persistent volumes, and the volume snapshots taken of them, stay in your account and stay billed. Remove them in Better Stack’s Volumes view, or look them up with Cloud.Volume / Cloud.VolumeSnapshot lookups and delete them through the SDK. See the KubernetesCluster reference.

Every cluster this stack creates carries an alchemy entry in its metadata (one of the 10 metadata slots), so a deploy that lost track of one finds it again and alchemy nuke lists only Alchemy-created clusters. Node pools have no metadata: their generated name identifies them. See the KubernetesCluster reference.