-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-p2p-clusters.sh
executable file
·278 lines (220 loc) · 8.42 KB
/
deploy-p2p-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
#!/bin/bash
# deploy-p2p-clusters.sh
# Cluster deployment script for the k3d-multicluster-playgorund GitHub repository
# https://github.com/southsidedean/linkerd-demos/tree/main/k3d-multicluster-playground
# Automates cluster creation, Linkerd installation and installs the Orders 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
# Viz Version
VIZ_VERSION=edge-24.10.1
set -xeuo pipefail
# Create the k3d cluster
k3d cluster delete orders warehouse
# 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 -c cluster/"$name".yaml --kubeconfig-update-default
k3d_api_ready "$name"
k3d_dns_ready "$name"
}
create_cluster orders
create_cluster warehouse
# add routes for each node in orders to each node in warehouse
kubectl --context=k3d-orders 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
kubectl --context=k3d-warehouse 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
k3d cluster list
# Configure the kubectl context
#kubectx -d orders
#kubectx -d warehouse
kubectx orders=k3d-orders
kubectx warehouse=k3d-warehouse
kubectx orders
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=orders
linkerd check --pre --context=warehouse
# 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 orders \
--set metadata.agentName=$CLUSTER1_NAME \
--set api.clientID=$API_CLIENT_ID \
--set api.clientSecret=$API_CLIENT_SECRET \
--set metrics.debugMetrics=true \
--set agent.logLevel=debug \
--set metrics.logLevel=debug \
linkerd-buoyant/linkerd-buoyant
helm install linkerd-buoyant \
--create-namespace \
--namespace linkerd-buoyant \
--kube-context warehouse \
--set metadata.agentName=$CLUSTER2_NAME \
--set api.clientID=$API_CLIENT_ID \
--set api.clientSecret=$API_CLIENT_SECRET \
--set metrics.debugMetrics=true \
--set agent.logLevel=debug \
--set metrics.logLevel=debug \
linkerd-buoyant/linkerd-buoyant
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context=orders
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context=warehouse
linkerd buoyant check --context orders
linkerd buoyant check --context warehouse
# 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=orders
kubectl apply -f linkerd-identity-secret.yaml --context=warehouse
kubectl get secrets -n linkerd --context=orders
kubectl get secrets -n linkerd --context=warehouse
# 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-hazl.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-hazl.yaml --context=orders
kubectl apply -f linkerd-control-plane-config-hazl.yaml --context=warehouse
watch -n 1 kubectl get pods -A -o wide --sort-by .metadata.namespace --context=orders
watch -n 1 kubectl get pods -A -o wide --sort-by .metadata.namespace --context=warehouse
# Run a Linkerd check after creating Control Planes
linkerd check --context orders
linkerd check --context warehouse
# 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: linkerd-buoyant
namespace: linkerd-buoyant
spec:
workloadSelector:
matchLabels: {}
EOF
kubectl apply -f linkerd-data-plane-config.yaml --context=orders
kubectl apply -f linkerd-data-plane-config.yaml --context=warehouse
# Monitor the status of the rollout of the Buoyant Cloud Metrics Daemonset
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context=orders
kubectl rollout status daemonset/buoyant-cloud-metrics -n linkerd-buoyant --context=warehouse
# Run a proxy check
sleep 75
linkerd check --proxy -n linkerd-buoyant --context orders
linkerd check --proxy -n linkerd-buoyant --context warehouse
# Install Linkerd Viz to Enable Success Rate Metrics
linkerd viz install --set linkerdVersion=$VIZ_VERSION --context orders | kubectl apply -f - --context orders
linkerd viz install --set linkerdVersion=$VIZ_VERSION --context warehouse | kubectl apply -f - --context warehouse
# 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 orders
kubectl apply -f buoyant-cloud-metrics.yaml --context warehouse
kubectl -n linkerd-buoyant rollout restart ds buoyant-cloud-metrics --context orders
kubectl -n linkerd-buoyant rollout restart ds buoyant-cloud-metrics --context warehouse
# Deploy the Orders application to both clusters
# Press CTRL-C to exit each watch command
kubectl apply -k orders/orders --context=orders
kubectl apply -k orders/warehouse --context=warehouse
watch -n 1 kubectl get pods -n orders -o wide --sort-by .spec.nodeName --context=orders
watch -n 1 kubectl get pods -n orders -o wide --sort-by .spec.nodeName --context=warehouse
# Deploy the Data Plane for the orders namespace
cat <<EOF > linkerd-data-plane-orders-config.yaml
---
apiVersion: linkerd.buoyant.io/v1alpha1
kind: DataPlane
metadata:
name: linkerd-orders
namespace: orders
spec:
workloadSelector:
matchLabels: {}
EOF
kubectl apply -f linkerd-data-plane-orders-config.yaml --context=orders
kubectl apply -f linkerd-data-plane-orders-config.yaml --context=warehouse
exit 0