Skip to content

Kubernetes

DigitalOcean Kubernetes (DOKS) runs the Kubernetes control plane for you. Your workloads run on node pools: groups of Droplets of one size, which DigitalOcean patches and can scale with demand. You pay for the nodes; the control plane is free unless you make it highly available.

src/cluster.ts
import * as DigitalOcean from "@alchemy.run/digitalocean";
export const K8s = DigitalOcean.Kubernetes.Cluster("K8s", {
region: "nyc3",
nodePool: { size: "s-2vcpu-4gb", count: 1 },
});

A cluster takes five to ten minutes to create. version pins a Kubernetes version; without it the cluster starts on the latest and a later version upgrades it in place.

const cluster = yield* K8s;
yield* DigitalOcean.Kubernetes.NodePool("Extra", {
clusterId: cluster.clusterId,
size: "s-1vcpu-2gb",
count: 2,
labels: { pool: "extra" },
});

Changing count scales the pool in place.

@alchemy.run/kubernetes applies Kubernetes objects to the cluster from the same Stack. Add Kubernetes.providers() to the Stack’s providers, then:

import * as Kubernetes from "@alchemy.run/kubernetes";
yield* Kubernetes.Manifest("Config", {
cluster,
manifest: {
apiVersion: "v1",
kind: "ConfigMap",
metadata: { name: "greeting", namespace: "default" },
data: { greeting: "hello" },
},
});

The cluster connects with your DigitalOcean token; there’s no kubeconfig to manage.

DigitalOcean.Kubernetes.Cluster("K8s", {
region: "nyc3",
nodePool: { size: "s-2vcpu-4gb", count: 1 },
registryEnabled: true,
});

registryEnabled installs a pull secret for the team’s registry in every namespace, so Pods can run registry.digitalocean.com/<registry>/<image>.

{ region: "nyc3", nodePool: { size: "s-2vcpu-4gb", count: 1 }, oneClickApps: ["metrics-server"] }

Newly listed apps install on the next deploy. DigitalOcean has no API to uninstall one, so removing a slug leaves the app running.

A log sink sends a cluster’s logs to OpenSearch:

const logs = yield* DigitalOcean.Monitoring.Destination("Logs", {
opensearch: { endpoint: "https://opensearch.example.com:9200", username: "alchemy", password },
});
yield* DigitalOcean.Monitoring.Sink("LogSink", {
destinationId: logs.destinationId,
resources: [{ urn: cluster.urn, name: "k8s" }],
});
  • Destroying a cluster leaves the load balancers and volumes its Services and PersistentVolumeClaims created, unless you set destroyAssociatedResources: true.
  • A new region, VPC or subnet replaces the cluster.

See Monitoring for alerts on the cluster’s nodes.