-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
174 lines (160 loc) · 4.54 KB
/
index.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";
import * as digitalocean from "@pulumi/digitalocean";
import * as kubernetes from "@pulumi/kubernetes";
import * as docluster from "./cluster/digitalocean";
import { Project } from "@pulumi/digitalocean";
const getEnvVariable = (name: string): string => {
const env = process.env[name];
if (!env) {
pulumi.log.error(`${name} environment variable is not set`);
throw Error;
}
return env;
};
const slackApiURL = getEnvVariable('SLACK_API_URL');
const doToken = getEnvVariable('DIGITALOCEAN_TOKEN');
// Define facts for the midl polkadot cluster.
const midlProject = {
name: "midl-polkadot",
description: "Project to confine midl polkadot/ksm resources",
environment: "Production",
purpose: "Other",
};
const midlVPC = {
name: "midl-polkadot-vpc",
region: "ams3",
};
const midlKubernetes = {
name: "midl-polkadot-k8s",
version: "1.21.2-do.2",
region: "ams3",
nodePool: {
name: "midl-polkadot-nodes",
// size could be found via do url:
// https://cloud.digitalocean.com/kubernetes/clusters/new?i=xxxx&nodePools=s-4vcpu-8gb:1&clusterVersion=1.21.2-do.2®ion=nyc1
size: "s-4vcpu-8gb",
nodeCount: 1,
},
};
// Create polkadot cluster on digitalocean.
const polkadotCluster = new docluster.MIDLCluster("midl-polkadot-cluster", {
project: midlProject,
vpc: midlVPC,
k8s: midlKubernetes,
doToken: doToken,
description: "Cluster on digitalocean to host polkadot/ksm validators."
});
// Get k8s config
const kubecluster = polkadotCluster.doK8s;
const kubeconfig = polkadotCluster.doKubeconfig;
const provider = new kubernetes.Provider("do-k8s", { kubeconfig });
//////////////
// Monitoring
/////////////
const alertTitle = '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} for {{ .CommonLabels.job }}'
const alertText = `{{ range .Alerts -}}
*Alert:* {{ .Annotations.title }}{{ if .Labels.severity }} - {{ .Labels.severity }}{{ end }}
*Description:* {{ .Annotations.description }}
*Details:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* {{ .Value }}
{{ end }}
{{ end }}
`
const alertmanagerConfig = {
global: {
slack_api_url: `${slackApiURL}`,
resolve_timeout: '5m',
},
route: {
group_by: ['alertname', 'service'],
group_wait: '30s',
group_interval: '5m',
repeat_interval: '12h',
receiver: 'null',
routes: [
{
match: {
alertname: 'Watchdog',
},
}
],
},
receivers: [
{
name: "null"
},{
name: 'midl_slack',
slack_configs: [
{
channel: '#infra',
send_resolved: true,
icon_url: 'https://avatars3.githubusercontent.com/u/3380462',
title: alertTitle,
text: alertText,
}
],
}
]
}
const monitorNodePool = "midl-polkadot-nodes"
const monitorNodeSelectorSpec = {
"doks.digitalocean.com/node-pool": monitorNodePool
}
const monitorNamespace = new kubernetes.core.v1.Namespace("monitoring", {
metadata: {
name: "monitoring",
}
},{
provider: provider,
dependsOn: [provider, kubecluster]
});
const monitorStack = new kubernetes.helm.v3.Chart("monitoring", {
chart: "kube-prometheus-stack",
fetchOpts:{
repo: "https://prometheus-community.github.io/helm-charts",
},
values: {
kubeApiServer: {
enabled: false
},
kubelet: {
enabled: false
},
kubeControllerManager: {
enabled: false
},
coreDns: {
enabled: false
},
kubeDns: {
enabled: true
},
kubeEtcd: {
enabled: false
},
kubeScheduler: {
enabled: false
},
kubeProxy: {
enabled: false
},
nodeExporter: {
// enabled: true,
hostNetwork: false,
},
alertmanager: {
config: alertmanagerConfig,
alertmanagerSpec: {
nodeSelector: monitorNodeSelectorSpec
},
},
prometheusOperator: {
nodeSelector: monitorNodeSelectorSpec
}
},
namespace: monitorNamespace.metadata.name
},{
provider: provider,
dependsOn: [monitorNamespace, provider, kubecluster],
});