-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_kubernetes_yaml.sh
executable file
·173 lines (160 loc) · 3.36 KB
/
generate_kubernetes_yaml.sh
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
#!/usr/bin/env bash
PROG="$0"
USAGE="WORKER_1 [WORKER_2...]"
errorout() {
echo "usage: ${PROG} -h" >&2
echo " or ${PROG} ${USAGE}" >&2
[ -n "$1" ] && echo "${PROG}: error: $@" >&2
exit 1
}
printhelp() {
cat <<EOF
usage: ${PROG} ${USAGE}
This generates some yaml that you can put in a file and apply to run in
a kubernetes cluster. For example:
$PROG worker-{30..37}.macc.test
That will generate the yaml to create 16 new deployments and 16 new
services on 8 worker nodes, each configured to connect to each other
node.
positional arguments:
WORKER... a complete list of worker nodes
optional arguments:
-h print this help text and exit
EOF
}
while getopts ':hn:' opt; do
case "$opt" in
h)
printhelp
exit 0
;;
?)
errorout "unrecognized argument: \`-$opt'"
;;
esac
done
shift $((OPTIND - 1))
main() {
INDICATORS=`join_with_comma "$@"`
for node in "$@"; do
print_kubernetes "$node"
done
}
join_with_comma() {
echo -n "http://network-indicator-${1//./-}:4567"
shift
for i in "$@"; do
echo -n ",http://network-indicator-${i//./-}:4567"
done
}
print_kubernetes() {
cat <<EOF
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: network-indicator-${1//./-}
spec:
selector:
matchLabels:
app: network-indicator
node: $1
template:
metadata:
labels:
app: network-indicator
node: $1
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchFields:
- key: metadata.name
operator: In
values:
- $1
containers:
- name: indicator
image: ghcr.io/mlibrary/kubernetes-network-test-indicator:1.0.0
env:
- name: RACK_ENV
value: production
ports:
- name: http
containerPort: 4567
livenessProbe:
httpGet:
path: /-/liveness
port: 4567
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: network-monitor-${1//./-}
spec:
selector:
matchLabels:
app: network-monitor
node: $1
template:
metadata:
labels:
app: network-monitor
node: $1
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchFields:
- key: metadata.name
operator: In
values:
- $1
containers:
- name: monitor
image: ghcr.io/mlibrary/kubernetes-network-test-monitor:1.0.0
env:
- name: RACK_ENV
value: production
- name: INDICATORS
value: $INDICATORS
ports:
- name: http
containerPort: 4568
livenessProbe:
httpGet:
path: /-/liveness
port: 4568
---
apiVersion: v1
kind: Service
metadata:
name: network-indicator-${1//./-}
spec:
selector:
app: network-indicator
node: $1
ports:
- name: http
port: 4567
---
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "4568"
prometheus.io/path: "/metrics"
name: network-monitor-${1//./-}
spec:
selector:
app: network-monitor
node: $1
ports:
- name: http
port: 4568
EOF
}
main "$@"