-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes_setup.sh
executable file
·54 lines (37 loc) · 2.39 KB
/
nodes_setup.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
#!/bin/bash
set -e
# Check if the script is executed at the root of the repository
if [[ ! -d ".git" ]]; then
COLOR_RED="\033[1;31m"
echo -e "${COLOR_RED}[ERROR] This script must be run from the root of the repository.${COLOR_RESET}" >&2
exit 1
fi
# Source the helper script
source ./scripts/helper_funcs.sh
assert_tools_installed talosctl yq
# Usage:
# Configure the control plane and worker nodes IPs in secrets/values.yaml which were assigned via DHCP
# when the OS was installed. Can be found in the VM screen.
# Run the script from the root of this repository. It will fetch the final IPs from the config files as well.
# --------------------------------CONFIG----------------------------------------
CURRENT_CONTROL_PLANE_IP=$(yq eval '.scriptConfigs.currentControlPlaneIp' secrets/values.yaml)
CURRENT_WORKER_1_IP=$(yq eval '.scriptConfigs.currentWorker1Ip' secrets/values.yaml)
CURRENT_WORKER_2_IP=$(yq eval '.scriptConfigs.currentWorker2Ip' secrets/values.yaml)
# --------------------------------CONFIG----------------------------------------
FINAL_CONTROL_PLANE_IP=$(yq eval '.machine.network.interfaces[0].addresses[0]' secrets/talos/controlplane.yaml | cut -d'/' -f1)
FINAL_WORKER_1_IP=$(yq eval '.machine.network.interfaces[0].addresses[0]' secrets/talos/worker-1.yaml | cut -d'/' -f1)
FINAL_WORKER_2_IP=$(yq eval '.machine.network.interfaces[0].addresses[0]' secrets/talos/worker-2.yaml | cut -d'/' -f1)
gum confirm "Applying configs to the nodes...? $CURRENT_CONTROL_PLANE_IP, $CURRENT_WORKER_1_IP, $CURRENT_WORKER_2_IP ?" || exit 1
log_exec talosctl apply-config --nodes "$CURRENT_CONTROL_PLANE_IP" --file "secrets/talos/controlplane.yaml" --insecure
log_exec talosctl apply-config --nodes "$CURRENT_WORKER_1_IP" --file "secrets/talos/worker-1.yaml" --insecure
log_exec talosctl apply-config --nodes "$CURRENT_WORKER_2_IP" --file "secrets/talos/worker-2.yaml" --insecure
log_info "Waiting 2m for the control plane to be ready... Eventually you have to retrigger this script if 2m was not enough"
sleep 120
log_exec talosctl config endpoint "$FINAL_CONTROL_PLANE_IP"
log_exec talosctl config node "$FINAL_CONTROL_PLANE_IP"
log_info "Bootstrapping the cluster now"
log_exec talosctl bootstrap
log_info "Checking the health of the cluster..."
log_exec talosctl health
log_exec talosctl kubeconfig -f ./secrets/kubeconfig
talosctl dashboard --nodes "$FINAL_CONTROL_PLANE_IP","$FINAL_WORKER_1_IP","$FINAL_WORKER_2_IP"