-
Notifications
You must be signed in to change notification settings - Fork 36
/
deployment.yaml.erb
490 lines (483 loc) · 15.4 KB
/
deployment.yaml.erb
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# TODO
# insert readiness checks
<%
def set_node_template_vars(values)
@Eth_Etherbase = values["geth"]["Eth_Etherbase"]
@Eth_MinerThreads = values["geth"]["Eth_MinerThreads"]
@Node_UserIdent = values["geth"]["Node_UserIdent"]
@Node_DataDir = values["geth"]["Node_DataDir"]
@Node_HTTPPort = values["geth"]["Node_HTTPPort"]
@Node_WSPort = values["geth"]["Node_WSPort"]
@NodeP2P_ListenAddr = values["geth"]["NodeP2P_ListenAddr"]
@NodeP2P_DiscoveryAddr = values["geth"]["NodeP2P_DiscoveryAddr"]
@Dashboard_Port = values["geth"]["Dashboard_Port"]
@Dashboard_Refresh = values["geth"]["Dashboard_Refresh"]
@nodePort_rpc = values["k8s"]["nodePort_rpc"]
@nodePort_ipc = values["k8s"]["nodePort_ipc"]
@replicas = values["k8s"]["replicas"]
return
end
-%>
<%- unless @config["keystore"]["secret"] -%>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: keystore-config
namespace: default
labels:
app: kuberneteth
name: keystore-config
data:
<%= @config["keystore"]["name"] %>: |-
<%- File.readlines("keystore/#{@config["keystore"]["name"]}").each do |line| -%>
<%= line -%>
<% end -%>
<% end -%>
<%- @nodes.each do |node| -%>
<%= set_node_template_vars(node.values.first) -%>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: gethconfig-<%= @Node_UserIdent %>
namespace: default
labels:
app: kuberneteth
name: gethconfig-<%= @Node_UserIdent %>
data:
gethconfig: |-
<%- File.readlines("#{@Node_UserIdent}.toml").each do |line| -%>
<%= line -%>
<% end -%>
<% end %>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: monitor-config
namespace: default
labels:
app: kuberneteth
name: monitor-config
data:
app.json: |-
[
<%- @nodes.each_with_index do |node, index| -%>
<%= set_node_template_vars(node.values.first) -%>
{
"name" : "<%= @Node_UserIdent %>",
"cwd" : ".",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"merge_logs" : false,
"watch" : false,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "<%= @Node_UserIdent %>-rpchost",
"RPC_PORT" : "<%= @Node_HTTPPort %>",
"LISTENING_PORT" : "<%= @NodeP2P_DiscoveryAddr %>",
"INSTANCE_NAME" : "<%= @Node_UserIdent %>",
"CONTACT_DETAILS" : "",
"WS_SERVER" : "localhost:3001",
"WS_SECRET" : "connectme",
"VERBOSITY" : <%= @config["monitor"]["verbosity"] %>
}
<%- if index == @nodes.length-1 -%>
}
<% else -%>
},
<% end -%>
<% end -%>
]
<%- unless @config["geth"]["network"]["public"] -%>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: genesis-config
namespace: default
labels:
app: kuberneteth
name: genesis-config
data:
Genesis-geth.json: |-
{
"config": {
"chainId": <%= @config["geth"]["network"]["id"] %>,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "<%= @config["geth"]["difficulty"] %>",
"extraData" : "0x",
"gasLimit" : "0x47e7c5",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc" : {
}
}
<% end -%>
<%- @nodes.each do |node| -%>
<%= set_node_template_vars(node.values.first) -%>
---
apiVersion: v1
kind: Service
metadata:
name: <%= @Node_UserIdent %>-svc
labels:
app: kuberneteth
tier: backend
name: <%= @Node_UserIdent %>-svc
spec:
selector:
app: kuberneteth
tier: backend
<%- if @nodePort_rpc || @nodePort_ipc -%>
type: NodePort
<% end -%>
ports:
- name: <%= @Node_UserIdent %>-jsonrpc
protocol: TCP
port: <%= @Node_HTTPPort %>
targetPort: <%= @Node_HTTPPort %>
<%- if @nodePort_rpc -%>
nodePort: <%= @nodePort_rpc %>
<% end -%>
- name: <%= @Node_UserIdent %>-wsrpc
protocol: TCP
port: <%= @Node_WSPort %>
targetPort: <%= @Node_WSPort %>
- name: <%= @Node_UserIdent %>-ipc-listen
protocol: UDP
port: <%= @NodeP2P_ListenAddr %>
targetPort: <%= @NodeP2P_ListenAddr %>
- name: <%= @Node_UserIdent %>-ipc-discovery
protocol: TCP
port: <%= @NodeP2P_DiscoveryAddr %>
targetPort: <%= @NodeP2P_DiscoveryAddr %>
<%- if @nodePort_ipc -%>
nodePort: <%= @nodePort_ipc %>
<% end -%>
<%- if @Dashboard_Port -%>
- name: <%= @Node_UserIdent %>-dashboard
protocol: TCP
port: <%= @Dashboard_Port %>
targetPort: <%= @Dashboard_Port %>
<% end -%>
<% end -%>
<%- unless @config["geth"]["network"]["public"] -%>
---
apiVersion: v1
kind: Service
metadata:
name: geth-bootnode-svc
labels:
app: kuberneteth
tier: backend
name: geth-bootnode-svc
spec:
selector:
app: kuberneteth
tier: backend
ports:
- name: geth-bootnode-ipc-discovery
protocol: UDP
port: <%= @config["bootnode"]["geth"]["NodeP2P_DiscoveryAddr"] %>
targetPort: <%= @config["bootnode"]["geth"]["NodeP2P_DiscoveryAddr"] %>
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: geth-boot-node-setup-pod
labels:
app: kuberneteth
name: bootnode-setup-pod
spec:
template:
metadata:
labels:
app: kuberneteth
name: bootnode-setup-pod
spec:
containers:
- name: geth-boot-node-setup-container
image: mmeister/geth-node:bootv2
command: [ "sh" ]
args:
- "-cx"
- "cd <%= @config["bootnode"]["geth"]["Node_DataDir"] %>;
echo \"enode://$(/bootnode -nodekeyhex <%= @config["bootnode"]["nodekeyhex"] %> -writeaddress)@$GETH_BOOTNODE_SVC_SERVICE_HOST:<%= @config["bootnode"]["geth"]["NodeP2P_DiscoveryAddr"] %>\" > enode.address;
set +x;
while true; do :; done;"
volumeMounts:
- name: geth-boot-node-persistent-storage
mountPath: <%= @config["bootnode"]["geth"]["Node_DataDir"] %>
volumes:
- name: geth-boot-node-persistent-storage
hostPath:
path: /var/lib/docker/geth-storage/bootnode
---
apiVersion: v1
kind: Pod
metadata:
name: geth-boot-node-pod
labels:
app: kuberneteth
name: geth-bootnode-pod
spec:
containers:
- name: geth-boot-node-container
image: mmeister/geth-node:bootv2
ports:
- containerPort: <%= @config["bootnode"]["geth"]["NodeP2P_ListenAddr"] %>
- containerPort: <%= @config["bootnode"]["geth"]["NodeP2P_DiscoveryAddr"] %>
protocol: UDP
command: [ "sh" ]
args:
- "-c"
- "cd <%= @config["bootnode"]["geth"]["Node_DataDir"] %>;
/geth --datadir <%= @config["bootnode"]["geth"]["Node_DataDir"] %> init /etc/geth/genesis/Genesis-geth.json;
/bootnode --nodekeyhex <%= @config["bootnode"]["nodekeyhex"] %> --addr \":<%= @config["bootnode"]["geth"]["NodeP2P_DiscoveryAddr"] %>\" --nat any --netrestrict <%= @config["geth"]["NodeP2P_Netrestrict"] %> --verbosity <%= @config["bootnode"]["verbosity"] %>;"
volumeMounts:
- name: geth-boot-node-persistent-storage
mountPath: <%= @config["bootnode"]["geth"]["Node_DataDir"] %>
- name: genesis-config-persistent-storage
mountPath: /etc/geth/genesis/Genesis-geth.json
subPath: Genesis-geth.json
- name: keystore-config-persistent-storage
mountPath: <%= @config["bootnode"]["geth"]["Node_DataDir"] %>/keystore/<%= @config["keystore"]["name"] %>
subPath: <%= @config["keystore"]["name"] %>
volumes:
- name: keystore-config-persistent-storage
<%- if @config["keystore"]["secret"] -%>
secret:
secretName: geth-key
<% else -%>
configMap:
name: keystore-config
items:
- key: <%= @config["keystore"]["name"] %>
path: <%= @config["keystore"]["name"] %>
<% end -%>
- name: geth-boot-node-persistent-storage
hostPath:
path: /var/lib/docker/geth-storage/bootnode
- name: genesis-config-persistent-storage
configMap:
name: genesis-config
items:
- key: Genesis-geth.json
path: Genesis-geth.json
<% end -%>
<%- @nodes.each do |node| -%>
<%= set_node_template_vars(node.values.first) -%>
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: geth-<%= @Node_UserIdent %>-deployment
spec:
strategy:
type: RollingUpdate
replicas: <%= @replicas %>
template:
metadata:
name: geth-<%= @Node_UserIdent %>-deployment
labels:
app: kuberneteth
tier: backend
name: <%= @Node_UserIdent %>-deployment
spec:
initContainers:
<%- unless @config["geth"]["network"]["public"] -%>
- name: <%= @Node_UserIdent %>-genesis-init-container
image: ethereum/client-go:<%= @config["geth"]["version"] %>
command: [ "sh" ]
args:
- "-cx"
- "if [ ! -f <%= @Node_DataDir %>/genesis_created ]; then
/usr/local/bin/geth --datadir <%= @Node_DataDir %> init /etc/geth/genesis/Genesis-geth.json;
touch <%= @Node_DataDir %>/genesis_created;
fi;"
volumeMounts:
- name: <%= @Node_UserIdent %>-persistent-storage
mountPath: <%= @Node_DataDir %>
- name: geth-boot-node-persistent-storage
mountPath: <%= @config["bootnode"]["geth"]["Node_DataDir"] %>
- name: genesis-config-persistent-storage
mountPath: /etc/geth/genesis/Genesis-geth.json
subPath: Genesis-geth.json
<% end -%>
containers:
- name: <%= @Node_UserIdent %>-container
image: ethereum/client-go:<%= @config["geth"]["version"] %>
command: [ "sh" ]
args:
- "-cx"
- "mkdir -p /etc/geth/<%= @Node_UserIdent %>;
cp /etc/gethconfigmap/<%= @Node_UserIdent %>/gethconfig.toml /etc/geth/<%= @Node_UserIdent %>;
<%- unless @config["geth"]["network"]["public"] -%>
ENODE=$(cat <%= @config["bootnode"]["geth"]["Node_DataDir"] %>/enode.address);
ENODE_ESC=$(echo $ENODE | sed 's@//@\\\\/\\\\/@g');
sed -i \"s/BootstrapNodes = \\[\\]/BootstrapNodes = [\\\"$ENODE_ESC\\\"]/g\" /etc/geth/<%= @Node_UserIdent %>/gethconfig.toml;
sed -i \"s/BootstrapNodesV5 = \\[\\]/BootstrapNodesV5 = [\\\"$ENODE_ESC\\\"]/g\" /etc/geth/<%= @Node_UserIdent %>/gethconfig.toml;
<% end -%>
/usr/local/bin/geth \
<%- if @Dashboard_Port || @Dashboard_Refresh -%>
--dashboard \
<% end -%>
<%- if @Eth_Etherbase && @Eth_MinerThreads -%>
--mine \
<% end -%>
<%- unless @config["geth"]["network"]["public"] -%>
--netrestrict <%= @config["geth"]["NodeP2P_Netrestrict"] %> \
<% end -%>
--verbosity <%= @config["geth"]["verbosity"] %> \
--config /etc/geth/<%= @Node_UserIdent %>/gethconfig.toml;"
ports:
- containerPort: <%= @Node_HTTPPort %>
- containerPort: <%= @Node_WSPort %>
- containerPort: <%= @NodeP2P_ListenAddr %>
protocol: UDP
- containerPort: <%= @NodeP2P_DiscoveryAddr %>
<%- if @Dashboard_Port -%>
- containerPort: <%= @Dashboard_Port %>
<% end -%>
volumeMounts:
- name: <%= @Node_UserIdent %>-persistent-storage
mountPath: <%= @Node_DataDir %>
- name: <%= @Node_UserIdent %>-config-persistent-storage
mountPath: /etc/gethconfigmap/<%= @Node_UserIdent %>
- name: keystore-config-persistent-storage
mountPath: <%= @Node_DataDir %>/keystore/<%= @config["keystore"]["name"] %>
subPath: <%= @config["keystore"]["name"] %>
<%- unless @config["geth"]["network"]["public"] -%>
- name: geth-boot-node-persistent-storage
mountPath: <%= @config["bootnode"]["geth"]["Node_DataDir"] %>
<% end -%>
volumes:
- name: keystore-config-persistent-storage
<%- if @config["keystore"]["secret"] -%>
secret:
secretName: geth-key
<% else -%>
configMap:
name: keystore-config
items:
- key: <%= @config["keystore"]["name"] %>
path: <%= @config["keystore"]["name"] %>
<% end -%>
<%- unless @config["geth"]["network"]["public"] -%>
- name: geth-boot-node-persistent-storage
hostPath:
path: /var/lib/docker/geth-storage/bootnode
- name: genesis-config-persistent-storage
configMap:
name: genesis-config
items:
- key: Genesis-geth.json
path: Genesis-geth.json
<% end -%>
- name: <%= @Node_UserIdent %>-persistent-storage
hostPath:
path: /var/lib/docker/geth-storage/<%= @Node_UserIdent %>
- name: <%= @Node_UserIdent %>-config-persistent-storage
configMap:
name: gethconfig-<%= @Node_UserIdent %>
items:
- key: gethconfig
path: gethconfig.toml
<% end -%>
---
apiVersion: v1
kind: Service
metadata:
name: <%= @config["monitor"]["name"] %>-svc
labels:
app: kuberneteth
tier: frontend
name: <%= @config["monitor"]["name"] %>-svc
spec:
selector:
app: kuberneteth
tier: frontend
<%- if @config["monitor"]["nodePort"] -%>
type: NodePort
<% end -%>
ports:
- name: <%= @config["monitor"]["name"] %>-port
protocol: TCP
port: 3001
<%- if @config["monitor"]["nodePort"] -%>
nodePort: <%= @config["monitor"]["nodePort"] %>
<% end -%>
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: <%= @config["monitor"]["name"] %>-deployment
spec:
strategy:
type: Recreate
replicas: 1
template:
metadata:
name: <%= @config["monitor"]["name"] %>-deployment
labels:
app: kuberneteth
tier: frontend
name: <%= @config["monitor"]["name"] %>-deployment
spec:
initContainers:
- name: <%= @config["monitor"]["name"] %>-init-container
image: mmeister/eth-net-intelligence-api
command: [ "sh" ]
args:
- "-cx"
- "cp -r /eth-net-intelligence-api/* /ethmonitor;
cp /monitor-configmap/app.json /ethmonitor/app.json;
<%- @nodes.each do |node| -%>
<%= set_node_template_vars(node.values.first) -%>
sed -i \"s/<%= @Node_UserIdent %>-rpchost/$<%= @Node_UserIdent.upcase %>_SVC_SERVICE_HOST/g\" /ethmonitor/app.json;
<% end -%>
exit 0;"
volumeMounts:
- name: monitor-configmap-volume
mountPath: /monitor-configmap/app.json
subPath: app.json
# we need to mount an extra volume to be able to change a value in the configmap
- name: monitor-config-persistent-storage
mountPath: /ethmonitor
containers:
- name: eth-netstats-container
image: mmeister/eth-netstats
ports:
- containerPort: 3001
env:
- name: WS_SECRET
value: "connectme"
- name: PORT
value: "3001"
- name: eth-net-intelligence-api-container
image: mmeister/eth-net-intelligence-api
volumeMounts:
- name: monitor-config-persistent-storage
mountPath: /eth-net-intelligence-api/app.json
subPath: app.json
volumes:
- name: monitor-configmap-volume
configMap:
name: monitor-config
items:
- key: app.json
path: app.json
- name: monitor-config-persistent-storage
hostPath:
path: /var/lib/docker/ethmonitor