0

Update a Node Pool in a Kubernetes Cluster

by
Published Dec 20, 2024

To update the name of a node pool, edit the tags applied to it, or adjust its number of nodes, send a PUT request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID` 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
 * Update a Node Pool in a Kubernetes Cluster
7
 * To update the name of a node pool, edit the tags applied to it, or adjust its
8
number of nodes, send a PUT request to
9
`/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID` with the
10
following attributes.
11

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

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