/
besu-statefulset.yaml
206 lines (206 loc) · 7.61 KB
/
besu-statefulset.yaml
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
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "besu.fullname" . }}
namespace: {{.Release.Namespace}}
spec:
replicas: {{.Values.besu.nodeCount}}
podManagementPolicy: Parallel
serviceName: {{ include "besu.fullname" .}}
selector:
matchLabels:
app: {{ include "besu.name" . }}
release: {{ .Release.Name }}
component: besu-node
app.kubernetes.io/name: {{ include "besu.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ include "besu.name" . }}
release: {{ .Release.Name }}
component: besu-node
app.kubernetes.io/name: {{ include "besu.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9545"
prometheus.io/path: "/metrics"
spec:
serviceAccountName: {{ include "besu.serviceAccountName" . }}
affinity:
{{ toYaml .Values.besu.affinity | nindent 8 }}
containers:
- env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: JAVA_ARGS
value: "-Dvertx.disableFileCPResolving=true -Dlog4j.shutdownHookEnabled=false --add-opens java.base/sun.security.provider=ALL-UNNAMED"
command:
- bash
- -xc
- |
{{- if .Values.besu.seedNetwork }}
bootnode={{include "besu.fullname" .}}-0
if [ ! -r /data/database/CURRENT ] && [ "$POD_NAME" = "$bootnode" ]; then
BOOT_NODE_ARGS=()
else
bootnode_ip=$(getent hosts {{include "besu.fullname" .}} | awk '{print $1}' | head -1)
bootnode_host=$(getent hosts $bootnode_ip |
awk '{print $NF}' | awk -F. '{print $1}')
if [ "$bootnode_host" = "$POD_NAME" ]; then
bootnode_ip=
bootnode_host=
elif echo $bootnode_host | grep -q {{include "besu.fullname" .}}; then
echo Bootnode to use $bootnode_host
else
bootnode_ip=
bootnode_host=
fi
while [ -z "$bootnode_ip" ]; do
sleep 1;
bootnode_ip=$(getent hosts {{include "besu.fullname" .}} | awk '{print $1}' | head -1)
bootnode_host=$(getent hosts $bootnode_ip |
awk '{print $NF}' | awk -F. '{print $1}')
if [ "$bootnode_host" = "$POD_NAME" ]; then
bootnode_ip=
bootnode_host=
elif echo $bootnode_host | grep -q {{include "besu.fullname" .}}; then
echo Bootnode to use $bootnode_host
else
bootnode_ip=
bootnode_host=
fi
done
bootnode_enode=$(cat /keys/{{include "besu.fullname" .}}-0.pub| sed -e 's/^0x//')
BOOT_NODE_ARGS=("enode://$bootnode_enode@$bootnode_ip:{{.Values.besu.p2p.port}}")
fi
{{- end }}
{{- range .Values.besu.additionalBootnodeUrls }}
bootnode_ip=$(getent hosts {{.host}} | awk '{print $1}' | head -1)
while [ -z "$bootnode_ip" ]; do
sleep 1
bootnode_ip=$(getent hosts {{.host}} | awk '{print $1}' | head -1)
done
BOOT_NODE_ARGS+=("enode://{{.pubkey}}@$bootnode_ip:{{.port}}")
{{- end}}
boot_node_string="${BOOT_NODE_ARGS[@]}"
boot_node_string=${boot_node_string// /,}
if [ -r /keys/${POD_NAME} ]; then
exec /opt/besu/bin/besu \
--node-private-key-file=/keys/${POD_NAME} \
--config-file=/etc/besu/config.toml \
--bootnodes "$boot_node_string"
else
exec /opt/besu/bin/besu \
--config-file=/etc/besu/config.toml \
--bootnodes "$boot_node_string"
fi
image: "{{.Values.besu.image.repository}}:{{.Values.besu.image.tag}}"
name: besu
ports:
- name: json-rpc
containerPort: {{ .Values.besu.rpc.port }}
protocol: TCP
- name: ws
containerPort: {{ .Values.besu.ws.port }}
protocol: TCP
- name: graphql
containerPort: {{ .Values.besu.graphql.port }}
protocol: TCP
- name: rlpx
containerPort: {{ .Values.besu.p2p.port }}
protocol: TCP
- name: discovery
containerPort: {{ .Values.besu.p2p.port }}
protocol: UDP
- name: metrics
containerPort: {{ .Values.besu.metrics.port }}
protocol: TCP
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
livenessProbe:
httpGet:
path: /liveness
port: {{ .Values.besu.rpc.port }}
initialDelaySeconds: 60
periodSeconds: 30
readinessProbe:
httpGet:
path: /readiness
port: {{ .Values.besu.rpc.port }}
initialDelaySeconds: 120
periodSeconds: 30
resources: {{ toYaml .Values.besu.resources | nindent 12 }}
volumeMounts:
- name: genesis
mountPath: /etc/genesis
readOnly: true
- name: config-toml
mountPath: /etc/besu
readOnly: true
{{- if .Values.besu.seedNetwork }}
- mountPath: /keys
name: networkkeys-config
readOnly: true
{{- end }}
- mountPath: {{ .Values.besu.dataPath | quote }}
name: data
- mountPath: /dev/random
name: dev-random
- mountPath: /dev/urandom
name: dev-urandom
restartPolicy: Always
volumes:
- name: config-toml
configMap:
name: {{ include "besu.fullname" . }}-config-toml
- name: dev-random
hostPath:
path: /dev/random
type: CharDevice
- name: dev-urandom
hostPath:
path: /dev/urandom
type: CharDevice
- name: genesis
configMap:
name: {{ include "besu.fullname" .}}-genesis
items:
- key: genesis.json
path: genesis.json
{{- if .Values.besu.seedNetwork }}
- name: networkkeys-config
secret:
secretName: {{ include "besu.fullname" .}}-keys
{{- end }}
{{- if not .Values.besu.persistence.enabled }}
- name: "data"
emptyDir: {}
{{- else }}
volumeClaimTemplates:
- metadata:
name: "data"
{{- if .Values.besu.persistence.annotations }}
annotations: {{- toYaml .Values.besu.persistence.annotations | nindent 10 }}
{{- end }}
spec:
accessModes: {{- toYaml .Values.besu.persistence.accessModes | nindent 10 }}
storageClassName: {{ default "gp2" .Values.besu.persistence.storageClass | quote }}
resources:
requests:
storage: {{ .Values.besu.persistence.size | quote }}
{{- end }}