This repository has been archived by the owner on Oct 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.yaml
238 lines (234 loc) · 5.92 KB
/
app.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
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
---
apiVersion: v1
kind: Service
metadata:
name: fb-0
labels:
app: fb-0
spec:
ports:
- port: 46656
name: p2p
- port: 46657
name: rpc
- port: 80
name: http
type: LoadBalancer
loadBalancerIP: 35.189.177.229
selector:
statefulset.kubernetes.io/pod-name: fb-0
---
apiVersion: v1
kind: Service
metadata:
name: fb-1
labels:
app: fb-1
spec:
ports:
- port: 46656
name: p2p
- port: 46657
name: rpc
- port: 80
name: http
type: LoadBalancer
loadBalancerIP: 35.234.5.77
selector:
statefulset.kubernetes.io/pod-name: fb-1
---
apiVersion: v1
kind: Service
metadata:
name: fb-2
labels:
app: fb-2
spec:
ports:
- port: 46656
name: p2p
- port: 46657
name: rpc
- port: 80
name: http
type: LoadBalancer
loadBalancerIP: 35.234.43.108
selector:
statefulset.kubernetes.io/pod-name: fb-2
---
apiVersion: v1
kind: Service
metadata:
name: fb-3
labels:
app: fb-3
spec:
ports:
- port: 46656
name: p2p
- port: 46657
name: rpc
- port: 80
name: http
type: LoadBalancer
loadBalancerIP: 35.229.165.115
selector:
statefulset.kubernetes.io/pod-name: fb-3
---
apiVersion: v1
kind: ConfigMap
metadata:
name: fb-config
data:
validators: "fb-0,fb-1,fb-2,fb-3"
ips: "35.189.177.229,35.234.5.77,35.234.43.108,35.229.165.115"
pub_validator_nginx.conf: |-
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
location ~ \.json$ { root /usr/share/nginx/; }
}
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: fb-budget
spec:
selector:
matchLabels:
app: fb
minAvailable: 2
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: fb
spec:
selector:
matchLabels:
app: fb
serviceName: forboled
podManagementPolicy: Parallel
replicas: 4
template:
metadata:
labels:
app: fb
spec:
containers:
- name: fb
imagePullPolicy: IfNotPresent
image: asia.gcr.io/forbole/forbole:latest
ports:
- containerPort: 46656
name: p2p
- containerPort: 46657
name: rpc
env:
- name: VALIDATORS
valueFrom:
configMapKeyRef:
name: fb-config
key: validators
- name: IPS
valueFrom:
configMapKeyRef:
name: fb-config
key: ips
command:
- bash
- "-c"
- |
set -ex
if [ ! -f /forbole/forboled/config/genesis.json ]; then
# fill genesis file with validators
IFS=',' read -ra IPS_ARR <<< "$IPS"
IFS=',' read -ra VALS_ARR <<< "$VALIDATORS"
for i in "${!VALS_ARR[@]}"; do
v="${VALS_ARR[$i]}"
if [ $HOSTNAME != $v ]; then
# wait until validator generates priv/pub key pair
set +e
curl -s --fail http://"${IPS_ARR[$i]}"/$v.json > /dev/null
ERR=$?
while [ "$ERR" != 0 ]; do
sleep 5
curl -s --fail http://"${IPS_ARR[$i]}"/$v.json > /dev/null
ERR=$?
done
set -e
# add validator to genesis file along with its pub_key
curl -s http://"${IPS_ARR[$i]}"/$v.json > /forbole/forboled/config/gentx/$v.json
fi
done
forboled init --gen-txs --chain-id=forbole-0 --home=/forbole/forboled
fi
forboled start --consensus.create_empty_blocks=false --home=/forbole/forboled
# fbcli rest-server --laddr=tcp://0.0.0.0:46655 --chain-id=forbole-0 --home=/forbole/fbcli
# forboled start --p2p.seeds="$seeds" --moniker=$HOSTNAME --proxy_app="unix:///socks/app.sock" --home=/forbole/forboled
# rm -f /socks/app.sock # remove old socket
# forbole start --address="unix:///socks/app.sock"
volumeMounts:
- name: fbdir
mountPath: /forbole
# - name: socksdir
# mountPath: /socks
- name: pub-validator
imagePullPolicy: IfNotPresent
image: nginx:latest
ports:
- containerPort: 80
command:
- bash
- "-c"
- |
set -ex
# fixes 403 Permission Denied (open() "/forbole/pub_validator.json" failed (13: Permission denied))
# => we cannot serve from /forbole, so we copy the file
mkdir -p /usr/share/nginx
cp /forbole/forboled/config/gentx/$HOSTNAME.json /usr/share/nginx/$HOSTNAME.json
nginx -g "daemon off;"
volumeMounts:
- name: fbdir
mountPath: /forbole
- mountPath: /etc/nginx/conf.d/pub_validator.conf
name: fbconfigdir
subPath: pub_validator_nginx.conf
initContainers:
- name: fb-gen-validator
image: asia.gcr.io/forbole/forbole:latest
imagePullPolicy: IfNotPresent
env:
- name: IPS
valueFrom:
configMapKeyRef:
name: fb-config
key: ips
command:
- bash
- "-c"
- |
set -ex
if [ ! -f /forbole/forboled/config/priv_validator.json ]; then
IFS=',' read -ra IPS_ARR <<< "$IPS"
ordinal=${HOSTNAME##*-}
forboled init gen-tx --name=$HOSTNAME --ip="${IPS_ARR[$ordinal]}" --home=/forbole/forboled --home-client=/forbole/fbcli
mv /forbole/forboled/config/gentx/gentx-$(forboled show_node_id --home=/forbole/forboled).json /forbole/forboled/config/gentx/$HOSTNAME.json
fi
volumeMounts:
- name: fbdir
mountPath: /forbole
volumes:
- name: fbconfigdir
configMap:
name: fb-config
# - name: socksdir
# emptyDir: {}
volumeClaimTemplates:
- metadata:
name: fbdir
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 2Gi