-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.ts
117 lines (106 loc) · 3.05 KB
/
cluster.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import * as gcp from "@pulumi/gcp";
import { NodePool } from "@pulumi/gcp/container";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import {
ComponentResource,
Config,
CustomResourceOptions,
} from "@pulumi/pulumi";
const project = new Config("gcp").require("project");
export class Cluster extends ComponentResource {
provider: k8s.Provider;
mainPool: NodePool;
constructor(name: string, opts: CustomResourceOptions = {}) {
super("taskforce:cluster", name, {}, opts);
const location = "europe-west4-a";
const engineVersion = gcp.container
.getEngineVersions({ location })
.then((v) => v.latestMasterVersion);
const cluster = new gcp.container.Cluster(
name,
{
location,
initialNodeCount: 1,
removeDefaultNodePool: true,
minMasterVersion: engineVersion,
},
{ parent: this }
);
const oauthScopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/ndev.clouddns.readwrite",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/servicecontrol",
];
/**
* This node pool is used for the permanent infrastructure:
* external-dns, contour, and provisioner.
*/
this.mainPool = new NodePool(
"main",
{
location,
cluster: cluster.name,
initialNodeCount: 1,
nodeConfig: {
labels: {
type: "main",
},
machineType: "e2-small",
preemptible: true,
oauthScopes,
},
},
{ parent: cluster, dependsOn: [cluster] }
);
const kubeconfig = pulumi
.all([cluster.name, cluster.endpoint, cluster.masterAuth])
.apply(([name, endpoint, masterAuth]) => {
const context = `${gcp.config.project}_${location}_${name}`;
return `apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ${masterAuth.clusterCaCertificate}
server: https://${endpoint}
name: ${context}
contexts:
- context:
cluster: ${context}
user: ${context}
name: ${context}
current-context: ${context}
kind: Config
preferences: {}
users:
- name: ${context}
user:
auth-provider:
config:
cmd-args: config config-helper --format=json
cmd-path: gcloud
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
`;
});
// Create a Kubernetes provider instance that uses our cluster from above.
this.provider = new k8s.Provider(
name,
{
kubeconfig,
suppressDeprecationWarnings: true,
},
{ parent: this, dependsOn: [this.mainPool] }
);
this.registerOutputs({
mainNodePool: this.mainPool,
provider: this.provider,
kubectl: kubeconfig,
});
}
}