-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinference-stack-deploy.sh
More file actions
2194 lines (1972 loc) · 104 KB
/
Copy pathinference-stack-deploy.sh
File metadata and controls
2194 lines (1972 loc) · 104 KB
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Colors
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
CYAN=$(tput setaf 6)
NC=$(tput sgr0)
# Copyright (C) 2024-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# Permission is granted for recipient to internally use and modify this software for purposes of benchmarking and testing on Intel architectures.
# This software is provided "AS IS" possibly with faults, bugs or errors; it is not intended for production use, and recipient uses this design at their own risk with no liability to Intel.
# Intel disclaims all warranties, express or implied, including warranties of merchantability, fitness for a particular purpose, and non-infringement.
# Recipient agrees that any feedback it provides to Intel about this software is licensed to Intel for any purpose worldwide. No permission is granted to use Intel’s trademarks.
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the code.
#############################################################################
# Usage Documentation
#############################################################################
# Intel AI for Enterprise Inference Stack Deployment
# This deployment automates the setup, reset, and update of a Kubernetes cluster with Enterprise Inference using Ansible playbooks.
# It includes functions for setting up a virtual environment, installing Kubernetes, deploying various components
# (e.g., Habana AI Operator, Ingress NGINX Controller, Keycloak, GenAI Gateway), and managing models and worker nodes.
# Prerequisites
# 1. Gaudi Driver update, Firmware update and Reboot
# 2. core/inventory/hosts.yaml file should be updated with the correct IP addresses of the nodes.
# Usage
# To run the deployment, execute the following command in your terminal:
# ./inference-stack-deploy.sh [OPTIONS]
# Options
# The script accepts the following command-line options:
# --cluster-url <URL>: The cluster URL (FQDN).
# --cert-file <path>: The full path to the certificate file.
# --key-file <path>: The full path to the key file.
# --keycloak-client-id <id>: The Keycloak client ID.
# --keycloak-admin-user <username>: The Keycloak admin username.
# --keycloak-admin-password <password>: The Keycloak admin password.
# --hugging-face-token <token>: The token for Huggingface.
# --models <models>: The models to deploy (comma-separated list of model numbers or names).
# --cpu-or-gpu <c/g>: Specify whether to run on CPU or GPU.
# Main Menu
# When you run the script, you will be presented with a main menu with the following options:
# 1. Provision Enterprise Inference Cluster: Perform a fresh installation of the Kubernetes cluster with Enterprise Inference.
# 2. Decommission Existing Cluster: Reset the existing Kubernetes cluster.
# 3. Update Deployed Inference Cluster: Update the existing Kubernetes cluster.
# Fresh Installation
# If you choose to perform a fresh installation, the script will prompt you for the necessary inputs and proceed with the following steps:
# 1. Prompt for Input: Collects the required inputs from the user.
# 2. Setup Initial Environment: Sets up the virtual environment and installs necessary dependencies.
# 3. Install Kubernetes: Installs Kubernetes and sets up the kubeconfig for the user.
# 4. Deploy Components: Deploys the selected components (Habana AI Operator, Ingress NGINX Controller, Keycloak, APISIX or GenAI Gateway and Models).
# Reset Cluster
# If you choose to reset the cluster, the script will:
# 1. Prompt for Confirmation: Asks for confirmation before proceeding with the reset.
# 2. Setup Initial Environment: Sets up the virtual environment and installs necessary dependencies.
# 3. Run Reset Playbook: Executes the Ansible playbook to reset the cluster.
# Update Existing Cluster
# If you choose to update the existing cluster, the script will present you with the following options:
# 1. Manage Worker Nodes: Add or remove worker nodes.
# 2. Manage Models: Add or remove models.
# Example
# To perform a fresh installation with specific parameters, you can run:
# ./inference-stack-deploy.sh --cluster-url "https://example.com" --cert-file "/path/to/cert.pem" --key-file "/path/to/key.pem" --keycloak-client-id "my-client-id" --keycloak-admin-user "user" --keycloak-admin-password "password" --hugging-face-token "token" --models "1,3,5" --cpu-or-gpu "g"
##############################################################################
#echo "All arguments: $@"
function usage() {
cat <<EOF
##############################################################################
--------------------------------------------------
Intel AI for Enterprise Inference Stack Deployment
--------------------------------------------------
Usage: ./inference-stack-deploy.sh [OPTIONS]
Automates the deployment and lifecycle management of Intel AI for Enterprise Inference Stack.
Options:
--cluster-url <URL> Cluster URL (FQDN).
--cert-file <path> Path to certificate file.
--key-file <path> Path to key file.
--keycloak-client-id <id> Keycloak client ID.
--keycloak-admin-user <user> Keycloak admin username.
--keycloak-admin-password <pw> Keycloak admin password.
--hugging-face-token <token> Huggingface token.
--models <models> Models to deploy (comma-separated).
--cpu-or-gpu <c/g> Run on CPU (c) or GPU (g).
Examples:
Setup cluster: ./inference-stack-deploy.sh --cluster-url "https://example.com" --cert-file "/path/cert.pem" --key-file "/path/key.pem" --keycloak-client-id "client-id" --keycloak-admin-user "user" --keycloak-admin-password "password" --hugging-face-token "token" --models "1,3,5" --cpu-or-gpu "g"
###############################################################################
EOF
}
HOMEDIR="$(pwd)"
KUBESPRAYDIR="$(dirname "$(realpath "$0")")/kubespray"
VENVDIR="$(dirname "$(realpath "$0")")/kubespray225-venv"
INVENTORY_PATH="${KUBESPRAYDIR}/inventory/mycluster/hosts.yaml"
# Set the default values for the parameters
cluster_url=""
cert_file=""
key_file=""
keycloak_client_id=""
keycloak_admin_user=""
keycloak_admin_password=""
hugging_face_token=""
models=""
model_name_list=""
cpu_or_gpu=""
deploy_kubernetes_fresh=""
deploy_habana_ai_operator=""
deploy_ingress_controller=""
deploy_genai_gateway=""
deploy_llm_models=""
deploy_istio=""
deploy_nri_balloon_policy=""
list_model_menu=""
apisix_enabled=""
ingress_enabled=""
deploy_keycloak=""
deploy_apisix=""
delete_pv_on_purge=""
prereq_executed=0
vault_pass_file=""
hugging_face_model_deployment=""
huggingface_model_id=""
huggingface_model_deployment_name=""
hugging_face_model_remove_deployment=""
hugging_face_model_remove_name=""
huggingface_tensor_parellel_size=""
deploy_ceph=""
gaudi_platform=""
gaudi_operator=""
gaudi2_values_file_path=""
gaudi3_values_file_path=""
python3_interpreter=""
skip_check=""
purge_inference_cluster=""
uninstall_ceph=""
read_config_file() {
local config_file="$HOMEDIR/inference-config.cfg"
if [ -f "$config_file" ]; then
echo "Configuration file found, setting vars!"
echo "---------------------------------------"
while IFS='=' read -r key value || [ -n "$key" ]; do
# Trim leading/trailing whitespace
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Set the variable using a temporary file
if [[ "$value" == "on" ]]; then
value="yes"
elif [[ "$value" == "off" ]]; then
value="no"
fi
printf "%s=%s\n" "$key" "$value" >> temp_env_vars
done < "$config_file"
# Load the environment variables from the temporary file
source temp_env_vars
rm temp_env_vars
local metadata_config_file="$HOMEDIR/inventory/metadata/inference-metadata.cfg"
if [ -f "$metadata_config_file" ]; then
echo "Metadata configuration file found, setting vars!"
echo "---------------------------------------"
while IFS='=' read -r key value || [ -n "$key" ]; do
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
printf "%s=%s\n" "$key" "$value" >> temp_env_vars_metadata
done < "$metadata_config_file"
source temp_env_vars_metadata
rm temp_env_vars_metadata
else
echo "Enterprise Inference Metadata configuration file not found"
exit 1
fi
if [[ -n "$vault_pass_code" ]]; then
echo "Vault password is set."
echo -n "$vault_pass_code" > .vault-passfile
vault_pass_file="$HOMEDIR/.vault-passfile"
else
echo "Vault password is not set. Please set it in the configuration file."
fi
INVENTORY_ALL_FILE="$HOMEDIR"/inventory/all.yml
if [[ -n "$http_proxy" ]]; then
sed -i -E "s|^[[:space:]]*#?[[:space:]]*http_proxy:.*|http_proxy: \"$http_proxy\"|" "$INVENTORY_ALL_FILE"
sed -i -E "/^env_proxy:/,/^[^[:space:]]/s|^[[:space:]]*http_proxy:.*| http_proxy: \"$http_proxy\"|" "$INVENTORY_ALL_FILE"
export http_proxy
fi
if [[ -n "$https_proxy" ]]; then
sed -i -E "s|^[[:space:]]*#?[[:space:]]*https_proxy:.*|https_proxy: \"$https_proxy\"|" "$INVENTORY_ALL_FILE"
sed -i -E "/^env_proxy:/,/^[^[:space:]]/s|^[[:space:]]*https_proxy:.*| https_proxy: \"$https_proxy\"|" "$INVENTORY_ALL_FILE"
export https_proxy
fi
if [[ -n "$no_proxy" ]]; then
sed -i -E "/^env_proxy:/,/^[^[:space:]]/s|^[[:space:]]*no_proxy:.*| no_proxy: \"$no_proxy\"|" "$INVENTORY_ALL_FILE"
export no_proxy
fi
case "$cpu_or_gpu" in
"c" | "cpu")
cpu_or_gpu="c"
deploy_habana_ai_operator="no"
;;
"g" | "gpu" | "gaudi2" | "gaudi3")
if [[ "$gaudi_platform" == "" ]]; then
if [[ "$cpu_or_gpu" == "gaudi2" || "$cpu_or_gpu" == "gpu" || "$cpu_or_gpu" == "g" ]]; then
gaudi_platform="gaudi2"
elif [[ "$cpu_or_gpu" == "gaudi3" ]]; then
gaudi_platform="gaudi3"
fi
fi
cpu_or_gpu="g"
deploy_habana_ai_operator="yes"
;;
*)
echo "Invalid value for cpu_or_gpu. It should be 'c' or 'cpu' for CPU, or 'g', 'gpu', 'gaudi2', or 'gaudi3' for GPU."
exit 1
;;
esac
case "$deploy_keycloak_apisix" in
"no")
deploy_apisix="no"
deploy_keycloak="no"
;;
"yes")
deploy_apisix="yes"
deploy_keycloak="yes"
;;
*)
echo "Incorrect value for deploy_keycloak_apisix"
exit 1
;;
esac
case "$deploy_genai_gateway" in
"no")
deploy_genai_gateway="no"
;;
"yes")
deploy_genai_gateway="yes"
;;
*)
echo "Incorrect value for deploy_genai_gateway"
exit 1
;;
esac
if [[ "$deploy_genai_gateway" == "yes" && "$deploy_keycloak_apisix" == "yes" ]]; then
echo -e "${YELLOW}--------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}| NOTICE: |${NC}"
echo -e "${YELLOW}| Both 'GenAI Gateway' and 'Keycloak & APISIX' cannot be enabled at |${NC}"
echo -e "${YELLOW}| the same time. |${NC}"
echo -e "${YELLOW}| Please select either GenAI Gateway or Keycloak & APISIX |${NC}"
echo -e "${YELLOW}--------------------------------------------------------------------------${NC}"
exit 1
fi
else
echo "Configuration file not found. Using default values or prompting for input."
fi
}
run_system_prerequisites_check() {
echo "Running system prerequisites check..."
echo "This will verify minimum system dependencies required for deployment."
local missing_deps=()
local warnings=()
echo "Checking essential system commands..."
# Wait for dpkg lock to be released if present
dpkg_lock_file="/var/lib/dpkg/lock"
dpkg_lock_frontend="/var/lib/dpkg/lock-frontend"
dpkg_lock_files=("$dpkg_lock_file" "$dpkg_lock_frontend")
timeout=300
for lock in "${dpkg_lock_files[@]}"; do
waited=0
if command -v lsof &>/dev/null; then
while lsof "$lock" &>/dev/null && [ $waited -lt $timeout ]; do
echo -e "${YELLOW}dpkg/apt process is using $lock (checked via lsof). Waiting for it to finish...${NC}"
sleep 2
waited=$((waited + 2))
done
elif command -v fuser &>/dev/null; then
while fuser "$lock" &>/dev/null && [ $waited -lt $timeout ]; do
echo -e "${YELLOW}dpkg/apt process is using $lock (checked via fuser). Waiting for it to finish...${NC}"
sleep 2
waited=$((waited + 2))
done
fi
if [ $waited -ge $timeout ]; then
if (command -v lsof &>/dev/null && lsof "$lock" &>/dev/null) || \
(command -v fuser &>/dev/null && fuser "$lock" &>/dev/null); then
echo -e "${RED}Timeout waiting for dpkg/apt lock file $lock to be released. Proceeding anyway.${NC}"
fi
fi
done
# Check for git
if ! command -v git &> /dev/null; then
missing_deps+=("git")
else
echo -e "${GREEN}✓ git found${NC}"
fi
# Check for python3 (version 3.10 or above) using configured interpreter
if [ -z "$python3_interpreter" ]; then
echo -e "${RED}✗ python3_interpreter not configured${NC}"
missing_deps+=("python3 (interpreter not configured)")
elif ! command -v "$python3_interpreter" &> /dev/null; then
echo -e "${RED}✗ configured python interpreter not found: $python3_interpreter${NC}"
missing_deps+=("python3")
else
# Check Python version using the configured interpreter
python_version=$($python3_interpreter -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
if $python3_interpreter -c "import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)" 2>/dev/null; then
echo -e "${GREEN}✓ python3 found (version $python_version) at $python3_interpreter${NC}"
else
echo -e "${RED}✗ python3 version $python_version found at $python3_interpreter, but version 3.10+ required${NC}"
missing_deps+=("python3 (version 3.10+)")
fi
fi
# Check for curl (needed for pip installation)
if ! command -v curl &> /dev/null; then
missing_deps+=("curl")
else
echo -e "${GREEN}✓ curl found${NC}"
fi
# Check internet connectivity (essential for Docker images, packages, repositories)
echo "Checking internet connectivity..."
if command -v curl &> /dev/null; then
# Test multiple reliable endpoints to ensure connectivity
if curl -s --connect-timeout 10 --max-time 15 https://google.com > /dev/null 2>&1 || \
curl -s --connect-timeout 10 --max-time 15 https://github.com > /dev/null 2>&1 || \
curl -s --connect-timeout 10 --max-time 15 https://registry-1.docker.io > /dev/null 2>&1; then
echo -e "${GREEN}✓ Internet connectivity confirmed${NC}"
else
echo -e "${RED}✗ No internet connectivity detected${NC}"
missing_deps+=("internet-connectivity")
fi
else
# If curl is not available, we'll check this later after curl is installed
warnings+=("Internet connectivity check skipped - curl not available")
fi
# Check if pip is available for the configured Python interpreter
if [ -n "$python3_interpreter" ]; then
if ! $python3_interpreter -m pip --version &> /dev/null; then
missing_deps+=("pip")
else
pip_version=$($python3_interpreter -m pip --version 2>/dev/null | cut -d' ' -f2)
echo -e "${GREEN}✓ pip found for $python3_interpreter (version $pip_version)${NC}"
fi
else
warnings+=("python3_interpreter not configured - pip check skipped")
fi
# Check for virtualenv capability (can be installed via pip)
if [ -n "$python3_interpreter" ] && ! $python3_interpreter -c "import venv" &> /dev/null && ! $python3_interpreter -c "import virtualenv" &> /dev/null; then
warnings+=("virtualenv not available - will be installed during setup")
else
echo -e "${GREEN}✓ virtualenv capability found${NC}"
fi
# Display warnings
if [ ${#warnings[@]} -gt 0 ]; then
echo -e "${YELLOW}Warnings:${NC}"
for warning in "${warnings[@]}"; do
echo -e "${YELLOW} ! $warning${NC}"
done
fi
echo "Updating system package lists..."
if command -v apt &> /dev/null; then
echo "Updating package lists using apt Ubuntu..."
if sudo apt update; then
echo -e "${GREEN}Package lists updated successfully${NC}"
else
echo -e "${YELLOW}Package list update failed, continuing anyway${NC}"
fi
elif command -v dnf &> /dev/null; then
echo "Updating package lists using dnf (RHEL/CentOS)..."
if sudo dnf check-update || [ $? -eq 100 ]; then
echo -e "${GREEN} Package lists updated successfully${NC}"
else
echo -e "${YELLOW} Package list update failed, continuing anyway${NC}"
fi
else
echo -e "${YELLOW}Unknown package manager, skipping package list update${NC}"
fi
echo ""
# Check if any critical dependencies are missing and handle appropriately
if [ ${#missing_deps[@]} -gt 0 ]; then
echo -e "${RED}Missing critical system dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e "${RED} - $dep${NC}"
done
echo ""
# Separate Python/pip issues, internet connectivity, and installable dependencies
local python_issues=()
local connectivity_issues=()
local installable_deps=()
for dep in "${missing_deps[@]}"; do
if [[ "$dep" == "python3"* ]]; then
python_issues+=("$dep")
elif [[ "$dep" == "internet-connectivity" ]]; then
connectivity_issues+=("$dep")
else
installable_deps+=("$dep")
fi
done
# Handle internet connectivity issues first - EXIT IMMEDIATELY (cannot be auto-fixed)
if [ ${#connectivity_issues[@]} -gt 0 ]; then
echo -e "${RED}Critical connectivity requirements not met:${NC}"
echo -e "${RED} - Internet connectivity is required for:${NC}"
echo -e "${RED} * Pulling Docker images${NC}"
echo -e "${RED} * Downloading packages and dependencies${NC}"
echo -e "${RED} * Accessing container registries${NC}"
echo -e "${RED} * Cloning Git repositories${NC}"
echo ""
echo -e "${YELLOW}Please ensure internet connectivity and try again.${NC}"
echo -e "${YELLOW}Common solutions:${NC}"
echo -e "${YELLOW} - Check network configuration${NC}"
echo -e "${YELLOW} - Verify firewall/proxy settings${NC}"
echo -e "${YELLOW} - Test: curl -I https://google.com${NC}"
exit 1
fi
# Handle Python issues first - EXIT IMMEDIATELY (no user acknowledgment)
if [ ${#python_issues[@]} -gt 0 ]; then
echo -e "${RED}Critical Python requirements not met:${NC}"
for issue in "${python_issues[@]}"; do
echo -e "${RED} - $issue${NC}"
done
echo ""
echo -e "${YELLOW}Python 3.10+ is required for Enterprise Inference deployment.${NC}"
echo -e "${YELLOW}Please install/configure Python 3.10+ and set python3_interpreter, then try again.${NC}"
echo -e "${YELLOW}RHEL: dnf install python3 python3-pip${NC}"
echo -e "${YELLOW}Ubuntu: apt update && apt install python3 python3-pip${NC}"
exit 1
fi
# Handle installable dependencies (git, curl) with user acknowledgment
if [ ${#installable_deps[@]} -gt 0 ]; then
echo -e "${YELLOW}The following dependencies can be installed automatically:${NC}"
for dep in "${installable_deps[@]}"; do
echo -e "${YELLOW} - $dep${NC}"
done
echo ""
install_deps="yes"
if [[ "$install_deps" =~ ^(yes|y|Y)$ ]]; then
# Separate pip from other dependencies
local pip_needed=false
local other_deps=()
for dep in "${installable_deps[@]}"; do
if [[ "$dep" == "pip" ]]; then
pip_needed=true
else
other_deps+=("$dep")
fi
done
# Install regular dependencies first (git, curl)
if [ ${#other_deps[@]} -gt 0 ]; then
if command -v dnf &> /dev/null; then
echo "Installing dependencies using dnf RHEL..."
sudo dnf install -y "${other_deps[@]}"
elif command -v apt &> /dev/null; then
echo "Installing dependencies using apt Ubuntu..."
sudo apt update && sudo apt install -y "${other_deps[@]}"
else
echo -e "${RED}Unsupported package manager. This script supports RHEL (dnf) and Ubuntu (apt) only.${NC}"
echo -e "${YELLOW}Please install manually:${NC}"
echo -e "${YELLOW} RHEL: dnf install ${other_deps[*]}${NC}"
echo -e "${YELLOW} Ubuntu: apt install ${other_deps[*]}${NC}"
exit 1
fi
fi
# Install pip using system package manager if needed
if [ "$pip_needed" = true ]; then
echo "Installing pip using system package manager..."
if command -v dnf &> /dev/null; then
python_version=$($python3_interpreter -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
if [[ "$python_version" == "3.11" ]]; then
echo "Installing python3.11-pip using dnf (RHEL 9)..."
if ! sudo dnf install -y python3.11-pip; then
echo -e "${RED}Failed to install python3.11-pip using dnf${NC}"
exit 1
fi
elif [[ "$python_version" == "3.12" ]]; then
echo "Installing python3.12-pip using dnf (RHEL 9)..."
if ! sudo dnf install -y python3.12-pip; then
echo -e "${RED}Failed to install python3.12-pip using dnf${NC}"
exit 1
fi
else
echo "Installing python3-pip using dnf (RHEL 9)..."
if ! sudo dnf install -y python3-pip; then
echo -e "${RED}Failed to install python3-pip using dnf${NC}"
exit 1
fi
fi
elif command -v apt &> /dev/null; then
echo "Installing python3-pip using apt (Ubuntu 22/24)..."
if ! sudo apt install -y python3-pip; then
echo -e "${RED}Failed to install python3-pip using apt${NC}"
exit 1
fi
else
echo -e "${RED}Unsupported system. This deployment only supports Ubuntu 22/24 and RHEL 9.4${NC}"
exit 1
fi
fi
# Verify installation
local install_failed=()
for dep in "${installable_deps[@]}"; do
if [[ "$dep" == "pip" ]]; then
if ! $python3_interpreter -m pip --version &> /dev/null; then
install_failed+=("$dep")
fi
else
if ! command -v "$dep" &> /dev/null; then
install_failed+=("$dep")
fi
fi
done
if [ ${#install_failed[@]} -gt 0 ]; then
echo -e "${RED}Failed to install: ${install_failed[*]}${NC}"
echo -e "${YELLOW}Please install them manually and try again.${NC}"
exit 1
else
echo -e "${GREEN}All dependencies installed successfully!${NC}"
fi
else
echo -e "${YELLOW}Installation cancelled. Please install the dependencies manually:${NC}"
echo -e "${YELLOW} RHEL: sudo dnf install ${installable_deps[*]}${NC}"
echo -e "${YELLOW} Ubuntu: sudo apt install ${installable_deps[*]}${NC}"
exit 1
fi
fi
fi
echo -e "${GREEN}System prerequisites check completed successfully.${NC}"
return 0
}
run_infrastructure_readiness_check() {
echo "Running infrastructure readiness check..."
echo "This will verify system compatibility and infrastructure requirements."
if [ ! -f "$HOMEDIR/inventory/hosts.yaml" ]; then
echo -e "${RED}Error: Inventory file not found at $HOMEDIR/inventory/hosts.yaml${NC}"
echo -e "${YELLOW}Please ensure the inventory file exists and contains the correct host information.${NC}"
return 1
fi
if ansible-playbook -i "${INVENTORY_PATH}" --become --become-user=root playbooks/inference-precheck.yml; then
echo -e "${GREEN}Infrastructure readiness check completed successfully.${NC}"
return 0
else
echo -e "${RED}Infrastructure readiness check failed. Please resolve the issues before proceeding.${NC}"
return 1
fi
}
setup_initial_env() {
echo "Setting up the Initial Environment..."
if [[ "$skip_check" != "true" ]]; then
echo "Performing initial system prerequisites check..."
if ! run_system_prerequisites_check; then
echo "System prerequisites check failed. Please install missing dependencies and try again."
exit 1
fi
echo "System prerequisites check completed successfully."
else
echo "Skipping system prerequisites check due to --skip-check argument."
fi
if [[ -n "$https_proxy" ]]; then
git config --global http.proxy "$https_proxy"
git config --global https.proxy "$https_proxy"
fi
if [ ! -d "$KUBESPRAYDIR" ]; then
git clone https://github.com/kubernetes-sigs/kubespray.git $KUBESPRAYDIR
if [ $? -ne 0 ] || [ ! -d "$KUBESPRAYDIR/.git" ]; then
echo -e "${RED}----------------------------------------------------------------------------${NC}"
echo -e "${RED}| NOTICE: Failed to clone Kubespray Repository. |${NC}"
echo -e "${RED}| Unable to proceed with Inference Stack Deployment |${NC}"
echo -e "${RED}| due to missing dependency |${NC}"
echo -e "${RED}----------------------------------------------------------------------------${NC}"
exit 1
fi
cd $KUBESPRAYDIR
git checkout v2.27.0
else
echo "Kubespray directory already exists, skipping clone."
cd $KUBESPRAYDIR
fi
if [[ -n "$https_proxy" ]]; then
git config --global --unset http.proxy
git config --global --unset https.proxy
fi
VENVDIR="$KUBESPRAYDIR/venv"
REMOTEDIR="/tmp/helm-charts"
if [ ! -d "$VENVDIR" ]; then
echo "Installing python3-venv package..."
if command -v apt &> /dev/null; then
python_version=$($python3_interpreter -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
sudo apt install -y python${python_version}-venv || sudo apt install -y python3-venv
fi
if $python3_interpreter -m venv $VENVDIR; then
echo "Virtual environment created within Kubespray directory."
else
echo -e "${RED}Failed to create virtual environment.${NC}"
exit 1
fi
else
echo "Virtual environment already exists within Kubespray directory, skipping creation."
fi
source $VENVDIR/bin/activate
echo "Attempting to activate the virtual environment..."
if [ -z "$VIRTUAL_ENV" ]; then
rm -rf "$KUBESPRAYDIR"
echo -e "${RED}----------------------------------------------------------------------------${NC}"
echo -e "${RED}| NOTICE: Failed to activate the virtual environment. |${NC}"
echo -e "${RED}| Please retrigger the Inference Stack Deployment |${NC}"
echo -e "${RED}| |${NC}"
echo -e "${RED}----------------------------------------------------------------------------${NC}"
exit 1
else
echo "Virtual environment activated successfully. Path: $VIRTUAL_ENV"
fi
export PIP_BREAK_SYSTEM_PACKAGES=1
$VENVDIR/bin/python3 -m pip install --upgrade pip
$VENVDIR/bin/python3 -m pip install -U -r requirements.txt
echo "Verifying Ansible Installation..."
if $VENVDIR/bin/python3 -c "import ansible" &> /dev/null; then
echo -e "${GREEN} Ansible installed successfully${NC}"
else
echo -e "${RED}----------------------------------------------------------------------------${NC}"
echo -e "${RED}| NOTICE: Ansible Installation Failed. |${NC}"
echo -e "${RED}| Unable to proceed with Inference Stack Deployment |${NC}"
echo -e "${RED}| due to missing dependency |${NC}"
echo -e "${RED}----------------------------------------------------------------------------${NC}"
exit 1
fi
echo -e "${GREEN} Enterprise Inference requirements installed.${NC}"
cp -r "$HOMEDIR"/deploy-* "$HOMEDIR"/helm-charts "$HOMEDIR"/scripts "$KUBESPRAYDIR"/
cp -r "$KUBESPRAYDIR"/inventory/sample/ "$KUBESPRAYDIR"/inventory/mycluster
cp "$HOMEDIR"/inventory/hosts.yaml $KUBESPRAYDIR/inventory/mycluster/
cp "$HOMEDIR"/inventory/metadata/addons.yml $KUBESPRAYDIR/inventory/mycluster/group_vars/k8s_cluster/addons.yml
cp "$HOMEDIR"/playbooks/* "$KUBESPRAYDIR"/playbooks/
gaudi2_values_file_path="$REMOTEDIR/vllm/gaudi-values.yaml"
gaudi3_values_file_path="$REMOTEDIR/vllm/gaudi3-values.yaml"
cp "$HOMEDIR"/inventory/metadata/addons.yml $KUBESPRAYDIR/inventory/mycluster/group_vars/k8s_cluster/addons.yml
cp "$HOMEDIR"/inventory/metadata/all.yml $KUBESPRAYDIR/inventory/mycluster/group_vars/all/all.yml
cp -r "$HOMEDIR"/roles/* $KUBESPRAYDIR/roles/
mkdir -p "$KUBESPRAYDIR/config"
chmod +x $HOMEDIR/scripts/generate-vault-secrets.sh
# Only generate vault secrets if vault.yml doesn't exist or is incomplete
vault_file="$HOMEDIR/inventory/metadata/vault.yml"
mandatory_keys=("litellm_master_key" "litellm_salt_key" "redis_password" "langfuse_secret_key" "langfuse_public_key" "postgresql_username" "postgresql_password" "clickhouse_username" "clickhouse_password" "langfuse_login" "langfuse_user" "langfuse_password" "minio_secret" "minio_user" "postgres_user" "postgres_password")
if [ ! -f "$vault_file" ]; then
echo "vault.yml not found at $vault_file, generating vault secrets..."
bash $HOMEDIR/scripts/generate-vault-secrets.sh
else
echo "Checking vault.yml for mandatory keys..."
missing_keys=()
for key in "${mandatory_keys[@]}"; do
if ! grep -q "^${key}:" "$vault_file"; then
missing_keys+=("$key")
fi
done
if [ ${#missing_keys[@]} -gt 0 ]; then
echo -e "${YELLOW}vault.yml exists but is missing mandatory keys: ${missing_keys[*]}${NC}"
echo "Regenerating vault.yml with all mandatory keys..."
bash $HOMEDIR/scripts/generate-vault-secrets.sh
else
echo -e "${GREEN}vault.yml exists and contains all mandatory keys. Skipping generation...${NC}"
fi
fi
if [ "$purge_inference_cluster" != "purging" ]; then
if [[ "$deploy_llm_models" == "yes" || "$deploy_keycloak_apisix" == "yes" || "$deploy_genai_gateway" == "yes" || "$deploy_observability" == "yes" || "$deploy_logging" == "yes" || "$deploy_ceph" == "yes" || "$deploy_istio" == "yes" ]]; then
if [ ! -s "$HOMEDIR/inventory/metadata/vault.yml" ]; then
echo -e "${YELLOW}----------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}| NOTICE: inventory/metadata/vault.yml is empty! |${NC}"
echo -e "${YELLOW}| Please refer to docs/configuring-vault-values.md for instructions on |${NC}"
echo -e "${YELLOW}| updating vault.yml |${NC}"
echo -e "${YELLOW}----------------------------------------------------------------------------${NC}"
exit 1
fi
fi
fi
cp "$HOMEDIR"/inventory/metadata/vault.yml $KUBESPRAYDIR/config/vault.yml
mkdir -p "$KUBESPRAYDIR/config/vars"
cp -r "$HOMEDIR"/inventory/metadata/vars/* $KUBESPRAYDIR/config/vars/
cp "$HOMEDIR"/playbooks/* "$KUBESPRAYDIR"/playbooks/
echo "Additional files and directories copied to Kubespray directory."
if [[ "$skip_check" != "true" ]]; then
echo "Performing infrastructure readiness check..."
if ! run_infrastructure_readiness_check; then
echo "Infrastructure readiness check failed. Please resolve the issues and try again."
exit 1
fi
else
echo "Skipping infrastructure readiness check due to --skip-check argument."
fi
echo "Infrastructure readiness check completed successfully."
gaudi2_values_file_path="$REMOTEDIR/vllm/gaudi-values.yaml"
gaudi3_values_file_path="$REMOTEDIR/vllm/gaudi3-values.yaml"
ansible-galaxy collection install community.kubernetes
}
invoke_prereq_workflows() {
if [ $prereq_executed -eq 0 ]; then
read_config_file "$@"
if [ -z "$cluster_url" ] || [ -z "$cert_file" ] || [ -z "$key_file" ] || [ -z "$keycloak_client_id" ] || [ -z "$keycloak_admin_user" ] || [ -z "$keycloak_admin_password" ]; then
echo "Some required arguments are missing. Prompting for input..."
prompt_for_input
fi
setup_initial_env "$@"
# Set the flag to 1 (executed)
prereq_executed=1
else
echo "Prerequisites have already been executed. Skipping..."
fi
}
check_cluster_state() {
echo "Checking the state of the Kubernetes cluster..."
ansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=root upgrade-cluster.yml --check
# Check the exit status of the Ansible playbook command
if [ $? -eq 0 ]; then
echo "Kubernetes cluster state check completed successfully."
else
echo "Kubernetes cluster state check indicates potential issues."
return 1 # Return a non-zero value to indicate potential issues
fi
}
run_reset_playbook() {
echo "Running the Ansible playbook to reset the cluster..."
delete_pv_on_purge="yes"
if [ "$uninstall_ceph" == "yes" ]; then
# Uninstall Ceph storage as part of cluster reset
echo "Running Ceph uninstall as part of cluster reset..."
uninstall_ceph_cluster
fi
ansible-playbook -i "${INVENTORY_PATH}" playbooks/deploy-keycloak-controller.yml --extra-vars "delete_pv_on_purge=${delete_pv_on_purge}"
ansible-playbook -i "${INVENTORY_PATH}" --become --become-user=root reset.yml -e "confirm_reset=yes reset_nodes=false"
# Check the exit status of the Ansible playbook command
if [ $? -eq 0 ]; then
echo "Cluster reset playbook execution completed successfully."
else
echo "Cluster reset playbook execution failed."
return 1 # Return a non-zero value to indicate failure
fi
}
reset_cluster() {
echo "-----------------------------------------------------------"
echo "| Purge Cluster! Intel AI for Enterprise! |"
echo "-----------------------------------------------------------"
echo "${YELLOW}NOTICE: You are initiating a reset of the existing Enterprise Inference Cluster."
echo "This action will erase all current configurations, services and resources. Potentially causing service interruptions and data loss. This operation cannot be undone. ${NC}"
read -p "Are you sure you want to proceed? (yes/no): " confirm_reset
if [[ "$confirm_reset" =~ ^(yes|y|Y)$ ]]; then
echo "Resetting the existing Enterprise Inference cluster..."
skip_check="true"
purge_inference_cluster="purging"
invoke_prereq_workflows "$@"
run_reset_playbook
# Check if the playbook execution was successful
if [ $? -eq 0 ]; then
echo "Cluster reset completed."
echo -e "${BLUE}-----------------------------------------------------------------${NC}"
echo -e "${GREEN}| Cluster Purge Initiated! |${NC}"
echo -e "${GREEN}| Preparing to transition the system. |${NC}"
echo -e "${GREEN}| This process may take some time depending on system resources |${NC}"
echo -e "${GREEN}| and other factors. Please standby... |${NC}"
echo -e "${BLUE}------------------------------------------------------------------${NC}"
echo ""
else
echo "Cluster reset failed."
fi
else
echo "Reset operation cancelled."
return
fi
}
run_fresh_install_playbook() {
echo "Running the cluster.yml playbook to set up the Kubernetes cluster..."
ansible-playbook -i "${INVENTORY_PATH}" --become --become-user=root cluster.yml
}
run_kube_conf_copy_playbook() {
echo "Running the setup-user-kubeconfig.yml playbook to set up kubeconfig for the user..."
ansible-playbook -i "${INVENTORY_PATH}" playbooks/setup-user-kubeconfig.yml
}
run_k8s_cluster_wait() {
echo "Waiting for Kubernetes control plane to become ready..."
ansible -i "${INVENTORY_PATH}" kube_control_plane -m wait_for -a "port=6443 timeout=600" --become --become-user=root
return $?
}
run_deploy_habana_ai_operator_playbook() {
echo "Running the deploy-habana-ai-operator.yml playbook to deploy the habana-ai-operator..."
ansible-galaxy collection install community.kubernetes
if [[ "$gaudi_platform" == "gaudi2" ]]; then
gaudi_operator="$gaudi2_operator"
elif [[ "$gaudi_platform" == "gaudi3" ]]; then
gaudi_operator="$gaudi3_operator"
else
gaudi_operator=""
fi
ansible-playbook -i "${INVENTORY_PATH}" --become --become-user=root deploy-habana-ai-operator.yml --extra-vars "gaudi_operator=${gaudi_operator}"
if [ $? -eq 0 ]; then
echo "The deploy-habana-ai-operator.yml playbook ran successfully."
else
echo "The deploy-habana-ai-operator.yml playbook encountered an error."
exit 1
fi
}
run_ingress_nginx_playbook() {
echo "Deploying the Ingress NGINX Controller..."
ansible-playbook -i "${INVENTORY_PATH}" playbooks/deploy-ingress-controller.yml --extra-vars "secret_name=${cluster_url} cert_file=${cert_file} key_file=${key_file}"
}
install_ansible_collection() {
echo "Installing community.general collection..."
ansible-galaxy collection install community.general
}
run_keycloak_playbook() {
echo "Deploying Keycloak using Ansible playbook..."
install_ansible_collection
ansible-playbook -i "${INVENTORY_PATH}" playbooks/deploy-keycloak-controller.yml
}
execute_and_check() {
local description=$1
local command=$2
local success_message=$3
local failure_message=$4
echo "$description"
$command
if [ $? -eq 0 ]; then
echo "$success_message"
else
echo "$failure_message"
exit 1
fi
}
create_keycloak_tls_secret_playbook() {
echo "Deploying Keycloak TLS secret playbook..."
echo "************************************"
ansible-playbook -i "${INVENTORY_PATH}" playbooks/deploy-keycloak-tls-cert.yml \
--extra-vars "secret_name=${cluster_url} cert_file=${cert_file} key_file=${key_file} keycloak_admin_user=${keycloak_admin_user} keycloak_admin_password=${keycloak_admin_password} keycloak_client_id=${keycloak_client_id} hugging_face_token=${hugging_face_token} model_name_list='${model_name_list//\ /,}' deploy_keycloak=${deploy_keycloak} deploy_apisix=${deploy_apisix} "
}
run_genai_gateway_playbook() {
echo "Deploying GenAI Gateway Service..."
echo "************************************"
ansible-playbook -i "${INVENTORY_PATH}" playbooks/deploy-genai-gateway.yml --extra-vars "secret_name=${cluster_url} cert_file=${cert_file} key_file=${key_file} deploy_genai_gateway=${deploy_genai_gateway} model_name_list='${model_name_list//\ /,}' " --vault-password-file "$vault_pass_file"
}
deploy_inference_llm_models_playbook() {
echo "Deploying Inference LLM Models playbook..."
install_true="true"
enable_cpu_balloons="false"
if [ "$cpu_or_gpu" == "c" ]; then
cpu_playbook="true"
gpu_playbook="false"
gaudi_deployment="false"
enable_cpu_balloons="true" # Enable NRI balloons for CPU deployments
huggingface_model_deployment_name="${huggingface_model_deployment_name}-cpu"
echo "${GREEN}CPU deployment detected - using generic NRI balloon policy${NC}"
fi
if [ "$cpu_or_gpu" == "g" ]; then
cpu_playbook="false"
gpu_playbook="true"
gaudi_deployment="true"
enable_cpu_balloons="false"
fi
if [ "$deploy_apisix" == "no" ]; then
apisix_enabled="false"
else
apisix_enabled="true"
fi
if [ "$deploy_keycloak" == "no" ]; then
ingress_enabled="true"
else
ingress_enabled="false"
fi
if [ "$deploy_observability" == "yes" ]; then
vllm_metrics_enabled="true"
else
vllm_metrics_enabled="false"
fi
if [[ "$gaudi_platform" == "gaudi2" ]]; then
gaudi_values_file=$gaudi2_values_file_path
elif [[ "$gaudi_platform" == "gaudi3" ]]; then
gaudi_values_file=$gaudi3_values_file_path
fi
echo "Ingress based Deployment: $ingress_enabled"
echo "APISIX Enabled: $apisix_enabled"
echo "Keycloak Enabled: $deploy_keycloak"
echo "Gaudi based: $gaudi_deployment"
echo "Model Metrics Enabled: $vllm_metrics_enabled"
echo "CPU NRI Balloons: $enable_cpu_balloons"
tags=""
for model in $model_name_list; do
tags+="install-$model,"
done
if [ -n "$huggingface_model_id" ] && [[ "$tags" != *"install-$huggingface_model_id"* ]]; then
tags+="install-$huggingface_model_deployment_name,"
fi
if [ "$deploy_keycloak" == "yes" ]; then