-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsetup_f5_eks.sh
executable file
·484 lines (432 loc) · 16.7 KB
/
setup_f5_eks.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
KUBERNETES_VERSION="1.29"
INSTANCE_TYPE="m5.2xlarge"
CHART_VERSION="5.9.8"
NODE_POOL="alpha.eksctl.io/nodegroup-name: standard-workers"
SOLR_REPLICAS=1
KAFKA_REPLICAS=1
PROMETHEUS="install"
SCRIPT_CMD="$0"
AWS_ACCOUNT=
REGION=us-west-2
CLUSTER_NAME=
NAMESPACE=default
UPGRADE=0
CREATE_MODE=
PURGE=0
FORCE=0
AMI=""
MY_VALUES=()
DRY_RUN=""
SOLR_DISK_GB=50
DEPLOY_ALB=
INTERNAL=false
function print_usage() {
CMD="$1"
ERROR_MSG="$2"
if [ "$ERROR_MSG" != "" ]; then
echo -e "\nERROR: $ERROR_MSG"
fi
echo -e "\nUse this script to install Fusion 5 on EKS; optionally create a EKS cluster in the process. We are using 1 vpc and 2 subnets from different AZs\n"
echo -e "\nUsage: $CMD [OPTIONS] ... where OPTIONS include:\n"
echo -e " -c Name of the EKS cluster (required)\n"
echo -e " -p AWS_ACCOUNT - profile (required)\n"
echo -e " -r Helm release name for installing Fusion 5, defaults to 'f5'\n"
echo -e " -n Kubernetes namespace to install Fusion 5 into, defaults to 'default'\n"
echo -e " -z AWS Region to launch the cluster in, defaults to 'us-west-2'\n"
echo -e " -i Instance type, defaults to 'm5.2xlarge'\n"
echo -e " -a AMI to use for the nodes, defaults to 'auto'\n"
echo -e " --deploy-alb Deploys alb ingress controller \n"
echo -e " --internal-alb Deploys and internal ALB\n"
echo -e " -h Hostname for the ingress to route requests to this Fusion cluster. It can be used with alb ingress controller "
echo -e " The hostname must be a public DNS record that can be updated to point to the ALB DNS name\n"
echo -e " --prometheus Enable Prometheus and Grafana for monitoring Fusion services, pass one of: install, provided, none;"
echo -e " defaults to 'install' which installs Prometheus and Grafana from the stable Helm repo,"
echo -e " 'provided' enables pod annotations on Fusion services to work with Prometheus but does not install anything\n"
echo -e " --version Fusion Helm Chart version, defaults to ${CHART_VERSION}\n"
echo -e " --values Custom values file containing config overrides; defaults to eks_<cluster>_<release>_fusion_values.yaml (can be specified multiple times)\n"
echo -e " --num-solr Number of Solr pods to deploy, defaults to 1\n"
echo -e " --num-kafka Number of Kafka pods to deploy, defaults to 1\n"
echo -e " --solr-disk-gb Size (in gigabytes) of the Solr persistent volume claim, defaults to 50\n"
echo -e " --node-pool Node pool label to assign pods to specific nodes, this option is only useful for existing clusters where you defined a custom node pool;"
echo -e " defaults to '${NODE_POOL}', wrap the arg in double-quotes\n"
echo -e " --create Create a cluster in EKS; provide the mode of the cluster to create, one of: demo\n"
echo -e " --upgrade Perform a Helm upgrade on an existing Fusion installation\n"
echo -e " --dry-run Perform a dry-run of the upgrade to see what would change\n"
echo -e " --purge Uninstall and purge all Fusion objects from the specified namespace and cluster\n"
echo -e " --force Force upgrade or purge a deployment if your account is not the value 'owner' label on the namespace\n"
}
if [ $# -gt 0 ]; then
while true; do
case "$1" in
-c)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -c parameter!"
exit 1
fi
CLUSTER_NAME="$2"
shift 2
;;
-n)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -n parameter!"
exit 1
fi
NAMESPACE="$2"
shift 2
;;
-p)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -p parameter!"
exit 1
fi
AWS_ACCOUNT="$2"
shift 2
;;
-r)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -r parameter!"
exit 1
fi
RELEASE="$2"
shift 2
;;
-z)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -z parameter!"
exit 1
fi
REGION="$2"
shift 2
;;
-h)
if [[ -h "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -h parameter!"
exit 1
fi
INGRESS_HOSTNAME="$2"
shift 2
;;
-i)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -i parameter!"
exit 1
fi
INSTANCE_TYPE="$2"
shift 2
;;
-a)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the -a parameter!"
exit 1
fi
AMI="$2"
shift 2
;;
--prometheus)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --prometheus parameter!"
exit 1
fi
PROMETHEUS="$2"
shift 2
;;
--num-solr)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --num-solr parameter!"
exit 1
fi
SOLR_REPLICAS=$2
shift 2
;;
--num-kafka)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --num-kafka parameter!"
exit 1
fi
KAFKA_REPLICAS=$2
shift 2
;;
--solr-disk-gb)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --solr-disk-gb parameter!"
exit 1
fi
SOLR_DISK_GB=$2
shift 2
;;
--node-pool)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --node-pool parameter!"
exit 1
fi
NODE_POOL="$2"
shift 2
;;
--version)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --version parameter!"
exit 1
fi
CHART_VERSION="$2"
shift 2
;;
--values)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --values parameter!"
exit 1
fi
MY_VALUES+=("$2")
shift 2
;;
--create)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Missing value for the --create parameter!"
exit 1
fi
CREATE_MODE="$2"
shift 2
;;
--deploy-alb)
DEPLOY_ALB=1
shift 1
;;
--internal-alb)
INTERNAL=true
shift 1
;;
--upgrade)
UPGRADE=1
shift 1
;;
--dry-run)
DRY_RUN="--dry-run"
shift 1
;;
--purge)
PURGE=1
shift 1
;;
--force)
FORCE=1
shift 1
;;
-help|-usage|--help|--usage)
print_usage "$SCRIPT_CMD"
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
#if [ "$CREATE_MODE" != "" ] && [ "$UPGRADE" == "1" ]; then
# print_usage "$SCRIPT_CMD" "Must specify either the --create or --upgrade options but not both!"
# exit 1
#fi
if [ "$CLUSTER_NAME" == "" ]; then
print_usage "$SCRIPT_CMD" "Please provide the EKS cluster name using: -c <cluster>"
exit 1
fi
if [ "$AWS_ACCOUNT" == "" ]; then
print_usage "$SCRIPT_CMD" "Please provide the AWS project name using: -p <project>"
exit 1
fi
valid="0-9a-zA-Z\-"
if [[ $NAMESPACE =~ [^$valid] ]]; then
echo -e "\nERROR: Namespace $NAMESPACE must only contain 0-9, a-z, A-Z, or dash!\n"
exit 1
fi
if [ -z ${RELEASE+x} ]; then
# keep "f5" as the default for legacy purposes when using the default namespace
if [ "${NAMESPACE}" == "default" ]; then
RELEASE="f5"
else
RELEASE="$NAMESPACE"
fi
fi
if [[ $RELEASE =~ [^$valid] ]]; then
echo -e "\nERROR: Release $RELEASE must only contain 0-9, a-z, A-Z, or dash!\n"
exit 1
fi
hash aws
has_prereq=$?
if [ $has_prereq == 1 ]; then
echo -e "\nERROR: Must install aws cli tools before proceeding with this script! See: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html"
exit 1
fi
hash eksctl
has_prereq=$?
if [ $has_prereq == 1 ]; then
echo -e "\nERROR: Must install eksctl before proceeding with this script! See: https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html"
exit 1
fi
hash aws-iam-authenticator
has_prereq=$?
if [ $has_prereq == 1 ]; then
echo -e "\nERROR: Must install aws-iam-authenticator before proceeding with this script! See: https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html"
exit 1
fi
# verify the user is logged in ...
who_am_i=$(aws --profile "${AWS_ACCOUNT}" --region "${REGION}" sts get-caller-identity --query "Arn" --output text)
if [ "${who_am_i}" == "" ]; then
echo -e "\nERROR: AWS user unknown, please use: 'aws configure' before proceeding with this script!"
exit 1
fi
echo -e "\nLogged in as: $who_am_i\n"
hash kubectl
has_prereq=$?
if [ $has_prereq == 1 ]; then
echo -e "\nERROR: Must install kubectl before proceeding with this script! See: https://kubernetes.io/docs/tasks/tools/install-kubectl/"
exit 1
fi
hash helm
has_prereq=$?
if [ $has_prereq == 1 ]; then
echo -e "\nERROR: Must install helm before proceeding with this script! See: https://helm.sh/docs/using_helm/#quickstart"
exit 1
fi
aws eks --profile "${AWS_ACCOUNT}" --region "${REGION}" list-clusters --query "clusters" | grep "${CLUSTER_NAME}" > /dev/null 2>&1
cluster_status=$?
if [ "$cluster_status" != "0" ]; then
if [ "$CREATE_MODE" == "" ]; then
CREATE_MODE="demo" # the default ...
fi
echo -e "\nLaunching an EKS cluster ${CLUSTER_NAME} ($CREATE_MODE) in project ${AWS_ACCOUNT} for deploying Lucidworks Fusion 5 ...\n"
if [ "$CREATE_MODE" == "demo" ] || [ "${CREATE_MODE}" == "multi_az" ]; then
#Creates EKS cluster
cat << EOF | eksctl create cluster --profile "${AWS_ACCOUNT}" --config-file -
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: ${CLUSTER_NAME}
region: ${REGION}
version: "${KUBERNETES_VERSION}"
nodeGroups:
- name: standard-workers
instanceType: ${INSTANCE_TYPE}
desiredCapacity: 3
iam:
attachPolicyARNs:
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
- arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
- arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy
privateNetworking: ${INTERNAL}
maxSize: 6
minSize: 0
EOF
else
echo -e "\nNo --create arg provided, assuming you want a multi-AZ, multi-NodePool cluster ..."
echo -e "Clusters with multiple NodePools not supported by this script yet! Please create the cluster and define the NodePools manually.\n"
exit 1
fi
echo -e "\nCluster '${CLUSTER_NAME}' deployed ... testing if it is healthy"
cluster_status=$(aws eks --profile "${AWS_ACCOUNT}" --region "${REGION}" describe-cluster --name "${CLUSTER_NAME}" --query "cluster.status" )
if [ "$cluster_status" != '"ACTIVE"' ]; then
echo -e "\nERROR: Status of EKS cluster ${CLUSTER_NAME} is suspect, status is: ${cluster_status}, check the AWS console before proceeding!\n"
exit 1
fi
else
if [ "$UPGRADE" == "0" ]; then
echo -e "\nEKS Cluster '${CLUSTER_NAME}' already exists, proceeding with Fusion 5 install ...\n"
fi
fi
aws eks --profile "${AWS_ACCOUNT}" --region "${REGION}" update-kubeconfig --name "${CLUSTER_NAME}"
current_cluster=$(kubectl config current-context)
echo -e "\nConfigured to use EKS cluster: ${current_cluster}"
if [ "$UPGRADE" == "0" ]; then
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin \
--user="$(aws --profile "${AWS_ACCOUNT}" --region "${REGION}" sts get-caller-identity --query "Arn")"
fi
NODE_GROUP_ARN=$(aws --profile "${AWS_ACCOUNT}" --region "${REGION}" cloudformation describe-stack-resource --stack-name eksctl-${CLUSTER_NAME}-nodegroup-standard-workers --logical-resource-id NodeInstanceRole --query 'StackResourceDetail.PhysicalResourceId' --output text)
echo -e "\nAdding aws-ebs-csi-driver to : ${current_cluster}"
eksctl --profile "${AWS_ACCOUNT}" --region "${REGION}" create addon --name aws-ebs-csi-driver --cluster "${CLUSTER_NAME}" --service-account-role-arn ${NODE_GROUP_ARN} --force
echo -e "\nInstalling Fusion 5.0 Helm chart ${CHART_VERSION} into namespace ${NAMESPACE} with release tag: ${RELEASE}"
INGRESS_VALUES=""
if [ "${DEPLOY_ALB}" == "1" ]; then
#Creating required ALB policy and attaching it to the Cluster Node Group
wget https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.6.1/docs/install/iam_policy.json -O alb-policy.json
POLICY_ARN=$(aws --profile "${AWS_ACCOUNT}" --region "${REGION}" iam create-policy --policy-name eksctl-${CLUSTER_NAME}-alb-policy --policy-document file://alb-policy.json --query 'Policy.Arn' --output text)
aws --profile "${AWS_ACCOUNT}" --region "${REGION}" iam attach-role-policy --role-name ${NODE_GROUP_ARN} --policy-arn ${POLICY_ARN}
#Installing ALB
echo -e "\nInstalling AWS Load Balancer Controller"
if ! helm repo list | grep -q "https://aws.github.io/eks-charts"; then
echo -e "\nAdding the Incubator chart repo to helm repo list"
helm repo add eks https://aws.github.io/eks-charts
fi
helm repo update
helm install aws-load-balancer-controller eks/aws-load-balancer-controller --namespace kube-system --set clusterName=${CLUSTER_NAME}
fi
ALB_SCHEME=""
if [ "${INTERNAL}" == true ]; then
ALB_SCHEME="internal"
else
ALB_SCHEME="internet-facing"
fi
if [ "${INGRESS_HOSTNAME}" != "" ]; then
API_GATEWAY_VALUES="api-gateway-values.yaml"
INGRESS_VALUES="${INGRESS_VALUES} --values api-gateway-values.yaml"
tee "${API_GATEWAY_VALUES}" << END
api-gateway:
service:
type: "NodePort"
ingress:
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: "${ALB_SCHEME}"
alb.ingress.kubernetes.io/success-codes: 200,301
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
enabled: true
host: "${INGRESS_HOSTNAME}"
path: "/"
END
fi
INGRESS_ARG=""
if [ ! -z "${INGRESS_HOSTNAME}" ]; then
INGRESS_ARG=" --ingress ${INGRESS_HOSTNAME} ${INGRESS_VALUES}"
fi
# Pass in custom values
VALUES_STRING=""
for v in "${MY_VALUES[@]}"; do
VALUES_STRING="${VALUES_STRING} --values ${v}"
done
UPGRADE_ARGS=""
if [ "${UPGRADE}" == "1" ]; then
UPGRADE_ARGS=" --upgrade"
if [ "${FORCE}" == "1" ]; then
UPGRADE_ARGS="$UPGRADE_ARGS --force"
fi
if [ "${DRY_RUN}" != "" ]; then
UPGRADE_ARGS="$UPGRADE_ARGS --dry-run"
fi
else
if [ "${PURGE}" == "1" ]; then
UPGRADE_ARGS=" --purge"
if [ "${FORCE}" == "1" ]; then
UPGRADE_ARGS="$UPGRADE_ARGS --force"
fi
fi
fi
if [ "${NODE_POOL}" == "" ]; then
# the user did not specify a node pool label, but our templating needs one
for node in $(kubectl get nodes --namespace="${NAMESPACE}" -o=name); do kubectl label "$node" fusion_node_type=system; done
NODE_POOL="fusion_node_type: system"
fi
# for debug only
#echo -e "Calling setup_f5_k8s.sh with: ${VALUES_STRING}${UPGRADE_ARGS}"
( "${SCRIPT_DIR}/setup_f5_k8s.sh" -c "$CLUSTER_NAME" -r "${RELEASE}" --provider "eks" -n "${NAMESPACE}" --node-pool "${NODE_POOL}" \
--version "${CHART_VERSION}" --prometheus "${PROMETHEUS}" --num-solr "${SOLR_REPLICAS}" --num-kafka "${KAFKA_REPLICAS}" --solr-disk-gb "${SOLR_DISK_GB}" ${VALUES_STRING}${INGRESS_ARG}${UPGRADE_ARGS} )
setup_result=$?
exit $setup_result