1 | |
2 | type Linode = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Kubernetes cluster |
7 | * Creates a Kubernetes cluster. |
8 | */ |
9 | export async function main( |
10 | auth: Linode, |
11 | apiVersion: "v4" | "v4beta", |
12 | body: { |
13 | control_plane?: { |
14 | acl?: { |
15 | addresses?: { ipv4?: string[]; ipv6?: string[] }; |
16 | enabled?: false | true; |
17 | "revision-id"?: string; |
18 | }; |
19 | high_availability?: false | true; |
20 | }; |
21 | k8s_version: string; |
22 | label: string; |
23 | node_pools: { |
24 | autoscaler?: { enabled?: false | true; max?: number; min?: number }; |
25 | count: number; |
26 | disks?: { size?: number; type?: "raw" | "ext4" }[]; |
27 | labels?: {}; |
28 | tags?: string[]; |
29 | taints?: { |
30 | effect: "NoSchedule" | "PreferNoSchedule" | "NoExecute"; |
31 | key: string; |
32 | value: string; |
33 | }[]; |
34 | type: string; |
35 | }[]; |
36 | region: string; |
37 | tags?: string[]; |
38 | tier?: "standard" | "enterprise"; |
39 | }, |
40 | ) { |
41 | const url = new URL(`https://api.linode.com/${apiVersion}/lke/clusters`); |
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 |
|