0

Add a Node Pool to a Kubernetes Cluster

by
Published Dec 20, 2024

To add an additional node pool to a Kubernetes clusters, send a POST request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools` with the following attributes.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Add a Node Pool to a Kubernetes Cluster
7
 * To add an additional node pool to a Kubernetes clusters, send a POST request
8
to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools` with the following
9
attributes.
10

11
 */
12
export async function main(
13
  auth: Digitalocean,
14
  cluster_id: string,
15
  body: { size?: string } & {
16
    id?: string;
17
    name?: string;
18
    count?: number;
19
    tags?: string[];
20
    labels?: {};
21
    taints?: {
22
      key?: string;
23
      value?: string;
24
      effect?: "NoSchedule" | "PreferNoSchedule" | "NoExecute";
25
    }[];
26
    auto_scale?: false | true;
27
    min_nodes?: number;
28
    max_nodes?: number;
29
    nodes?: {
30
      id?: string;
31
      name?: string;
32
      status?: { state?: "provisioning" | "running" | "draining" | "deleting" };
33
      droplet_id?: string;
34
      created_at?: string;
35
      updated_at?: string;
36
    }[];
37
  },
38
) {
39
  const url = new URL(
40
    `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/node_pools`,
41
  );
42

43
  const response = await fetch(url, {
44
    method: "POST",
45
    headers: {
46
      "Content-Type": "application/json",
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57