0

Delete a Node Pool in a Kubernetes Cluster

by
Published Dec 20, 2024

To delete a node pool, send a DELETE request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID`. A 204 status code with no body will be returned in response to a successful request. Nodes in the pool will subsequently be drained and deleted.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete a Node Pool in a Kubernetes Cluster
7
 * To delete a node pool, send a DELETE request to
8
`/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID`.
9

10
A 204 status code with no body will be returned in response to a successful
11
request. Nodes in the pool will subsequently be drained and deleted.
12

13
 */
14
export async function main(
15
  auth: Digitalocean,
16
  cluster_id: string,
17
  node_pool_id: string,
18
) {
19
  const url = new URL(
20
    `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/node_pools/${node_pool_id}`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "DELETE",
25
    headers: {
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36