about summary refs log tree commit diff
path: root/terraform/configure-k3s.sh
diff options
context:
space:
mode:
authormakefunstuff <[email protected]>2024-07-18 21:09:37 +0200
committermakefunstuff <[email protected]>2024-07-18 21:09:37 +0200
commit07822ea3f2239cf9cd3335ad2d7fb0aab7a3e1dc (patch)
treee9f4e9c69d3653b19139da565e5426b2c70806f8 /terraform/configure-k3s.sh
parenta52d9c49b7f4166b18a49b4907a2b0afba3aac05 (diff)
downloadk3s-lab-07822ea3f2239cf9cd3335ad2d7fb0aab7a3e1dc.tar.gz
infra updates
Diffstat (limited to '')
-rwxr-xr-xterraform/configure-k3s.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/terraform/configure-k3s.sh b/terraform/configure-k3s.sh
new file mode 100755
index 0000000..76076d7
--- /dev/null
+++ b/terraform/configure-k3s.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Get the IP addresses from Terraform output
+MASTER_IP=$(terraform output -json k8s_node_ips | jq -r '.[0]')
+WORKER_IPS=$(terraform output -json k8s_node_ips | jq -r '.[1,2]')
+
+# Set up the master node
+ssh ubuntu@$MASTER_IP <<EOF
+sudo /usr/local/bin/k3s-install.sh
+EOF
+
+# Get the K3s token
+K3S_TOKEN=$(ssh ubuntu@$MASTER_IP "sudo cat /var/lib/rancher/k3s/server/node-token")
+
+# Join worker nodes to the cluster
+for WORKER_IP in $WORKER_IPS; do
+  ssh ubuntu@$WORKER_IP <<EOF
+sudo K3S_URL=https://$MASTER_IP:6443 K3S_TOKEN=$K3S_TOKEN /usr/local/bin/k3s-install.sh
+EOF
+done
+
+echo "K3s cluster setup completed. Master node IP: $MASTER_IP"