-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-httproute-clusters.sh
executable file
·367 lines (285 loc) · 10 KB
/
deploy-httproute-clusters.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
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
#!/bin/bash
# deploy-httproute-clusters.sh
# Cluster deployment script for the k3d-multicluster-playground GitHub repository
# https://github.com/southsidedean/linkerd-demos/tree/main/k3d-multicluster-playground
# Automates cluster creation, Linkerd installation and installs the k3d-$CLUSTER_B_NAME application
# Tom Dean | Buoyant
# Last edit: 10/8/2024
# Let's set some variables!
# BEL: Stable
#BEL_VERSION=enterprise-2.16.0
#CLI_VERSION=install
#MC_VERSION=enterprise
# BEL: Preview
BEL_VERSION=preview-24.10.4
CLI_VERSION=install-preview
MC_VERSION=preview
# Cluster Naming Variables
CLUSTER_A_PREFIX=cluster-a
CLUSTER_B_NAME=cluster-b
# Cluster A Count
CLUSTER_A_COUNT=3
# Viz Version
VIZ_VERSION=edge-24.10.1
# Let's go!
set -xeuo pipefail
# Create the k3d cluster
for i in `seq 1 $CLUSTER_A_COUNT`
do
k3d cluster delete $CLUSTER_A_PREFIX$i
done
k3d cluster delete $CLUSTER_B_NAME
# This section creates the k3d clusters
# From https://gist.github.com/olix0r/2f2db5bb60731b5b3fd584523f53a60c
# olix0r/flat-network.sh
# which is forked from alpeb/flat-network.sh
# Minor tweaks to fit this application
k3d_api_ready() {
name=$1
for i in {1..6} ; do
if kubectl --context=k3d-$name cluster-info >/dev/null ; then return ; fi
sleep 10
done
exit 1
}
k3d_dns_ready() {
name=$1
while [ $(kubectl --context=k3d-$name get po -n kube-system -l k8s-app=kube-dns -o json |jq '.items | length') = "0" ]; do sleep 1 ; done
kubectl --context=k3d-$name wait pod --for=condition=ready \
--namespace=kube-system --selector=k8s-app=kube-dns \
--timeout=1m
}
create_cluster() {
name=$1
k3d cluster create $name -c cluster/$name.yaml --kubeconfig-update-default
k3d_api_ready "$name"
k3d_dns_ready "$name"
}
create_cluster $CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
create_cluster $CLUSTER_A_PREFIX$i
done
# add routes for each node in cluster-b to all cluster-a nodes
kubectl --context=k3d-$CLUSTER_B_NAME get node -o json | \
jq -r '.items[] | .metadata.name + "\t" + .spec.podCIDR + "\t" + (.status.addresses[] | select(.type == "InternalIP") | .address)' | \
while IFS=$'\t' read -r sname scidr sip; do
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl --context=k3d-$CLUSTER_A_PREFIX$i get node -o json | \
jq -r '.items[] | .metadata.name + "\t" + .spec.podCIDR + "\t" + (.status.addresses[] | select(.type == "InternalIP") | .address)' | \
while IFS=$'\t' read -r tname tcidr tip; do
docker exec "${sname}" ip route add "${tcidr}" via "${tip}"
docker exec "${tname}" ip route add "${scidr}" via "${sip}"
done
done
done
k3d cluster list
# Configure the kubectl context
#kubectx -d k3d-$CLUSTER_B_NAME
#kubectx -d $CLUSTER_A_PREFIX$i
#kubectx k3d-$CLUSTER_B_NAME=k3d-k3d-$CLUSTER_B_NAME
#kubectx $CLUSTER_A_PREFIX$i=k3d-$CLUSTER_A_PREFIX$i
#kubectx k3d-$CLUSTER_B_NAME
kubectx
# Create fresh root certificates for mTLS
cd certs
rm -f *.{crt,key}
step certificate create root.linkerd.cluster.local ca.crt ca.key \
--profile root-ca --no-password --insecure
step certificate create identity.linkerd.cluster.local issuer.crt issuer.key \
--profile intermediate-ca --not-after 8760h --no-password --insecure \
--ca ca.crt --ca-key ca.key
ls -la
cd ..
# Read in license, Buoyant Cloud and cluster name information from the settings.sh file
source settings.sh
# Install the CLI
curl https://enterprise.buoyant.io/$CLI_VERSION | sh
export PATH=~/.linkerd2/bin:$PATH
linkerd version
# Perform pre-installation checks
linkerd check --pre --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
linkerd check --pre --context k3d-$CLUSTER_A_PREFIX$i
done
# Install Buoyant Enterprise Linkerd Operator and Buoyant Cloud Agents using Helm
# Debug metrics are enabled to use the Buoyant Cloud Grafana instance
helm repo add linkerd-buoyant https://helm.buoyant.cloud
helm repo update
helm install linkerd-buoyant \
--create-namespace \
--namespace linkerd-buoyant \
--kube-context k3d-$CLUSTER_B_NAME \
--set metadata.agentName=$CLUSTER_B_NAME \
--set api.clientID=$API_CLIENT_ID \
--set api.clientSecret=$API_CLIENT_SECRET \
linkerd-buoyant/linkerd-buoyant
for i in `seq 1 $CLUSTER_A_COUNT`
do
helm install linkerd-buoyant \
--create-namespace \
--namespace linkerd-buoyant \
--kube-context k3d-$CLUSTER_A_PREFIX$i \
--set metadata.agentName=$CLUSTER_A_PREFIX$i \
--set api.clientID=$API_CLIENT_ID \
--set api.clientSecret=$API_CLIENT_SECRET \
linkerd-buoyant/linkerd-buoyant
done
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context k3d-$CLUSTER_A_PREFIX$i
done
linkerd buoyant check --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
linkerd buoyant check --context k3d-$CLUSTER_A_PREFIX$i
done
# Create linkerd-identity-issuer secret using root certificates
cat <<EOF > linkerd-identity-secret.yaml
apiVersion: v1
data:
ca.crt: $(base64 < certs/ca.crt | tr -d '\n')
tls.crt: $(base64 < certs/issuer.crt| tr -d '\n')
tls.key: $(base64 < certs/issuer.key | tr -d '\n')
kind: Secret
metadata:
name: linkerd-identity-issuer
namespace: linkerd
type: kubernetes.io/tls
EOF
kubectl apply -f linkerd-identity-secret.yaml --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl apply -f linkerd-identity-secret.yaml --context k3d-$CLUSTER_A_PREFIX$i
done
kubectl get secrets -n linkerd --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl get secrets -n linkerd --context k3d-$CLUSTER_A_PREFIX$i
done
# Create and apply Control Plane CRDs to trigger BEL Operator
# This will create the Control Plane on the cluster
# Press CTRL-C to exit each watch command
cat <<EOF > linkerd-control-plane-config.yaml
apiVersion: linkerd.buoyant.io/v1alpha1
kind: ControlPlane
metadata:
name: linkerd-control-plane
spec:
components:
linkerd:
version: $BEL_VERSION
license: $BUOYANT_LICENSE
controlPlaneConfig:
proxy:
image:
version: $BEL_VERSION
identityTrustAnchorsPEM: |
$(sed 's/^/ /' < certs/ca.crt )
identity:
issuer:
scheme: kubernetes.io/tls
destinationController:
additionalArgs:
# - -ext-endpoint-zone-weights
EOF
kubectl apply -f linkerd-control-plane-config.yaml --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl apply -f linkerd-control-plane-config.yaml --context k3d-$CLUSTER_A_PREFIX$i
done
watch -n 1 kubectl get pods -A -o wide --sort-by .metadata.namespace --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
watch -n 1 kubectl get pods -A -o wide --sort-by .metadata.namespace --context k3d-$CLUSTER_A_PREFIX$i
done
# Run a Linkerd check after creating Control Planes
linkerd check --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
linkerd check --context k3d-$CLUSTER_A_PREFIX$i
done
# Create the Data Plane for the linkerd-buoyant namespace
cat <<EOF > linkerd-data-plane-config.yaml
---
apiVersion: linkerd.buoyant.io/v1alpha1
kind: DataPlane
metadata:
name: dataplane-linkerd-buoyant
namespace: linkerd-buoyant
spec:
workloadSelector:
matchLabels: {}
EOF
kubectl apply -f linkerd-data-plane-config.yaml --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl apply -f linkerd-data-plane-config.yaml --context k3d-$CLUSTER_A_PREFIX$i
done
# Monitor the status of the rollout of the Buoyant Cloud Metrics Daemonset
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context k3d-$CLUSTER_A_PREFIX$i
done
# Run a proxy check
sleep 75
linkerd check --proxy -n linkerd-buoyant --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
linkerd check --proxy -n linkerd-buoyant --context k3d-$CLUSTER_A_PREFIX$i
done
# Install Linkerd Viz to Enable Success Rate Metrics
linkerd viz install --set linkerdVersion=$VIZ_VERSION --context k3d-$CLUSTER_B_NAME | kubectl apply -f - --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
linkerd viz install --set linkerdVersion=$VIZ_VERSION --context k3d-$CLUSTER_A_PREFIX$i | kubectl apply -f - --context k3d-$CLUSTER_A_PREFIX$i
done
# Enable Inbound Latency Metrics
# These are disabled by default in the Buoyant Cloud Agent
# Patch with the buoyant-cloud-metrics.yaml manifest
# Restart the buoyant-cloud-metrics daemonset
kubectl apply -f buoyant-cloud-metrics.yaml --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl apply -f buoyant-cloud-metrics.yaml --context k3d-$CLUSTER_A_PREFIX$i
done
kubectl -n linkerd-buoyant rollout restart ds buoyant-cloud-metrics --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl -n linkerd-buoyant rollout restart ds buoyant-cloud-metrics --context k3d-$CLUSTER_A_PREFIX$i
done
# Deploy the orders application to cluster-b
# Deploy the warehouse application to all the cluster-a clusters
# Press CTRL-C to exit each watch commands
kubectl apply -k orders/orders-httproute --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl apply -k orders/warehouse-httproute --context k3d-$CLUSTER_A_PREFIX$i
done
watch -n 1 kubectl get pods -n orders -o wide --sort-by .spec.nodeName --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
watch -n 1 kubectl get pods -n orders -o wide --sort-by .spec.nodeName --context k3d-$CLUSTER_A_PREFIX$i
done
# Deploy the Data Plane for the orders namespace to cluster-b
cat <<EOF > linkerd-data-plane-orders-config.yaml
---
apiVersion: linkerd.buoyant.io/v1alpha1
kind: DataPlane
metadata:
name: dataplane-orders
namespace: orders
spec:
workloadSelector:
matchLabels: {}
EOF
kubectl apply -f linkerd-data-plane-orders-config.yaml --context k3d-$CLUSTER_B_NAME
for i in `seq 1 $CLUSTER_A_COUNT`
do
kubectl apply -f linkerd-data-plane-orders-config.yaml --context k3d-$CLUSTER_A_PREFIX$i
done
exit 0