Skip to content
betterstack-alchemyUnofficial

Cloud.KubernetesCluster

Kind ResourceType id BetterStack.Cloud.KubernetesClusterSource src/Cloud/KubernetesCluster.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_CLOUD_BILLABLE=1 because it bills; live runs need the owner's go-ahead (test/Cloud/KubernetesCluster.test.ts).

A managed Kubernetes cluster: a control plane on a single server, and groups of workers added with KubernetesNodePool. Better Stack runs the control plane for you, for free; workers are ordinary servers billed at ordinary server prices and count against your server quotas (both from Better Stack’s “Get started with managed Kubernetes”). Deleting the cluster removes its control plane, workers, snapshots and the load balancers its Services created, but persistent volumes and the volume snapshots of your VolumeSnapshots stay in your account and stay billed: remove them in Volumes (or with Cloud.Volume / Cloud.VolumeSnapshot lookups and the SDK). Deploying blocks until the control plane is running (up to 45 minutes), and fails with a typed WaitFailed when it ends failed or degraded, or WaitTimeout past the budget. Workers come from node pools, each waited for on its own.

Versions. version is the Kubernetes major.minor, such as 1.36, defaulting to the newest; Cloud.listKubernetesVersion lists them. Patch releases are applied for you. A higher version upgrades in place (one minor version at a time; a snapshot of the control plane is taken first), and the deploy waits until the cluster is running on it.

What changes in place. name, metadata and apiAllowedCidrs (the ranges allowed to reach the Kubernetes API; the API never returns this prop, so it is compared with what was last deployed, and the ranges in force show under apiEndpoint.apiAllowedCidrs) update in place; version upgrades; networkIds and firewallIds (at most one firewall, applied to the workers) attach and detach one at a time — both read back empty while the cluster has no workers. podCidr, 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: a replace that keeps an explicit name deletes the old cluster first.

Connecting. endpoint is the API server URL; kubeconfig (Redacted, admin access), certificateAuthorityData and connection (endpoint + CA + the admin token, as AWS.EKS.Cluster and GCP.Container.Cluster expose it) come from the kubeconfig endpoint, read once the cluster is running (it answers a typed 409 until the control plane has issued its admin token: retried, bounded). Reach the API from addresses in apiAllowedCidrs.

Credentials: the deploy never rotates the kubeconfig on its own. Set rotateCredentials to a new value to rotate it once (the previous admin credentials stop working); a rotation done in the console or CLI is read on the next deploy, without a replace.

A cluster with one node pool

const cluster = yield* BetterStack.Cloud.KubernetesCluster("k8s", {
apiAllowedCidrs: ["203.0.113.0/24"],
});
yield* BetterStack.Cloud.KubernetesNodePool("workers", {
kubernetesClusterId: cluster.id,
serverType: "AM4",
nodeCount: 2,
});

Pinned version, custom ranges, on a private network

const network = yield* BetterStack.Cloud.Network("private", {
ipPrefix: "10.0.0.0",
ipPrefixLength: 24,
});
yield* BetterStack.Cloud.KubernetesCluster("platform", {
name: "platform",
version: "1.36",
podCidr: "10.100.0.0/16",
serviceCidr: "10.101.0.0/16",
networkIds: [network.id],
});

The kubeconfig for kubectl in a CI step or a Service’s env

const cluster = yield* BetterStack.Cloud.KubernetesCluster("k8s", {});
// env: { KUBECONFIG_DATA: cluster.kubeconfig }
// cluster.connection: { endpoint, certificateAuthorityData, auth: { kind: "token", token } }

Reference a cluster by id

const existing = BetterStack.Cloud.KubernetesCluster.lookup({ id: "42" });

Reference a cluster by name (fails with AmbiguousLookup when several share it)

const byName = BetterStack.Cloud.KubernetesCluster.lookup({ name: "production" });

apiAllowedCidrs string[]

The IP ranges allowed to reach the cluster's Kubernetes API, as 1 to 50 IPv4 or IPv6 CIDRs. Responses show the current ranges under endpoint.

availabilityZone string

Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.

firewallIds string[]

The IDs of the firewalls attached to the workers. The list is empty while the cluster has no workers.

metadata CreateKubernetesClusterRequestMetadataMap

Your own tags, up to 10 string pairs. An update replaces all tags. The keys kubernetes-cluster, kubernetes-node-pool and kubernetes-service-uid are reserved for Better Stack and can't be set.

name string

The cluster's name, up to 255 characters, unique among the organization's clusters that aren't failed or destroyed. Defaults to a unique name generated from the stack, stage and logical id. Changes in place.

networkIds string[]

The IDs of the private networks attached to the cluster. The list is empty while the cluster has no workers. Must be networks of the cluster's team.

podCidr string

The IPv4 range for pods. Can't overlap service_cidr, the range we use for the cluster, or a network you attach. Can't be changed after the cluster is created.

rotateCredentials string

Rotate the credentials: every change of this value after create (for example a date, "2026-12") calls the API's rotate operation once on the next deploy, and the new secrets replace the old ones in the attributes (and so in every env that references them). Leaving it out, or keeping the same value, never rotates. A rotation done in the console or CLI is simply read on the next deploy.

serviceCidr string

The IPv4 range for Kubernetes services. Can't overlap pod_cidr, the range we use for the cluster, or a network you attach. Can't be changed after the cluster is created.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

version string

The Kubernetes version as major and minor number, such as 1.36. Defaults to the newest version. List the versions with betterstack kubernetes-version list.

apiEndpoint KubernetesClusterEndpoint always set

Where the Kubernetes API is, as the API returns it: hostname, port (always 6443) and the apiAllowedCidrs currently in force.

availabilityZone string always set

Availability zone the resource lives in, such as us-west-2a.

certificateAuthorityData string always set

The base64-encoded PEM CA bundle of the API server, from the kubeconfig's certificate-authority-data; undefined when the cluster's CA isn't available (the kubeconfig then skips the certificate check).

connection KubernetesClusterConnection always set

How to reach and authenticate to the API server, shaped like the connection of AWS.EKS.Cluster and GCP.Container.Cluster (@alchemy.run/kubernetes's Connection): endpoint, certificateAuthorityData, and auth from the kubeconfig's user — a bearer token, or a client-cert — with the secret Redacted.

endpoint string always set

The Kubernetes API server URL, https://<hostname>:6443, built from the API's endpoint.hostname and endpoint.port. undefined until the control plane has one.

id string always set

The cluster's ID.

kubeconfig Redacted<string> always set

A kubeconfig with admin access to the cluster (GET /v1/kubernetes-clusters/{id}/kubeconfig), ready for kubectl --kubeconfig or KUBECONFIG. Carries the admin credentials.

availableVersions string[]

The versions you can upgrade the cluster to now. Holds the next minor version once we offer it.

createdAt string

When the cluster was created.

firewallIds string[]

The IDs of the firewalls attached to the workers. The list is empty while the cluster has no workers.

kubeconfigRotatedAt string | null

When the admin credentials of the kubeconfig were first issued or last rotated, or null before they're issued.

latestSnapshotAt string | null

When the newest available snapshot of the control plane was created, or null when there is none.

metadata KubernetesClusterMetadataMap

Your own tags, up to 10 string pairs. An update replaces all tags. The keys kubernetes-cluster, kubernetes-node-pool and kubernetes-service-uid are reserved for Better Stack and can't be set.

name string

The cluster's name, up to 255 characters. Must be unique among the organization's clusters that aren't failed or destroyed.

networkIds string[]

The IDs of the private networks attached to the cluster. The list is empty while the cluster has no workers. Must be networks of the cluster's team.

nodePools KubernetesClusterNodePoolsItem[]

The cluster's node pools, sorted by name, each with its workers. Deleted node pools aren't listed.

nodesReady number

How many workers were ready when we last checked.

nodesTotal number

How many workers the cluster has now. Each node pool's node_count says how many it should have.

patchVersion string | null

The exact Kubernetes build we installed for version, such as v1.37.2+k3s1.

podCidr string

The IPv4 range for pods. Can't overlap service_cidr, the range we use for the cluster, or a network you attach. Can't be changed after the cluster is created.

preUpgradeSnapshotId string | null

The ID of the snapshot we create before the upgrade. Restore it to roll the upgrade back.

serviceCidr string

The IPv4 range for Kubernetes services. Can't overlap pod_cidr, the range we use for the cluster, or a network you attach. Can't be changed after the cluster is created.

status string

The state of the cluster's control plane. The cluster is ready when it's running and every node pool has node_count workers that are all ready. - provisioning: We're creating the control plane and the workers. - running: The control plane works. Check node_pools to see whether the workers are ready. - degraded: The control plane or some workers aren't healthy. status_message says which. - upgrading: We're upgrading the control plane and then the workers. - restoring: We're restoring the control plane from a snapshot. - failed: We couldn't create the cluster. status_message says why. - destroyed: The cluster is deleted.

statusMessage string | null

What went wrong while creating, scaling or running the cluster, or null.

teamId string

The ID of the team that owns the cluster. betterstack team list shows it.

updatedAt string

When the cluster was last updated.

version string

The Kubernetes version as major and minor number, such as 1.36. Defaults to the newest version. List the versions with betterstack kubernetes-version list.

KubernetesCluster.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

availabilityZone string

Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.