0

Delete a Cluster and All of its Associated Resources (Dangerous)

by
Published Dec 20, 2024

To delete a Kubernetes cluster with all of its associated resources, send a DELETE request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/destroy_with_associated_resources/dangerous`. A 204 status code with no body will be returned in response to a successful request.

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 Cluster and All of its Associated Resources (Dangerous)
7
 * To delete a Kubernetes cluster with all of its associated resources, send a
8
DELETE request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/destroy_with_associated_resources/dangerous`.
9
A 204 status code with no body will be returned in response to a successful request.
10

11
 */
12
export async function main(auth: Digitalocean, cluster_id: string) {
13
  const url = new URL(
14
    `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/destroy_with_associated_resources/dangerous`,
15
  );
16

17
  const response = await fetch(url, {
18
    method: "DELETE",
19
    headers: {
20
      Authorization: "Bearer " + auth.token,
21
    },
22
    body: undefined,
23
  });
24
  if (!response.ok) {
25
    const text = await response.text();
26
    throw new Error(`${response.status} ${text}`);
27
  }
28
  return await response.json();
29
}
30