0

Delete a Kubernetes Cluster

by
Published Dec 20, 2024

To delete a Kubernetes cluster and all services deployed to it, send a DELETE request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID`. 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 Kubernetes Cluster
7
 * To delete a Kubernetes cluster and all services deployed to it, send a DELETE
8
request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID`.
9

10
A 204 status code with no body will be returned in response to a successful
11
request.
12

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

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