From 657f8e52665c5ba6e8b223c17c90fba1d2cc5544 Mon Sep 17 00:00:00 2001 From: ghe0 Date: Wed, 12 Mar 2025 20:15:05 +0200 Subject: [PATCH] added kubernetes example --- kubernetes/README.md | 14 ++++++++++++++ kubernetes/create_vms.sh | 36 ++++++++++++++++++++++++++++++++++++ kubernetes/deploy.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 kubernetes/README.md create mode 100755 kubernetes/create_vms.sh create mode 100755 kubernetes/deploy.sh diff --git a/kubernetes/README.md b/kubernetes/README.md new file mode 100644 index 0000000..3c590f7 --- /dev/null +++ b/kubernetes/README.md @@ -0,0 +1,14 @@ +# WireGuard cluster example + +This example will create 5 kubernetes nodes using k3s: a master and 4 workers. +All VMs have public IPs, which can be used to publish ports. + +To create the VMs, run: +``` +./create_vms.sh +``` + +And to deploy: +``` +./deploy.sh +``` diff --git a/kubernetes/create_vms.sh b/kubernetes/create_vms.sh new file mode 100755 index 0000000..84ed687 --- /dev/null +++ b/kubernetes/create_vms.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e +mkdir -p tmp + +detee-cli vm deploy --hostname k3s-master --vcpus 4 \ + --memory 4000 --disk 20 --location Random --public-ip | + tail -1 > tmp/master_ssh_command && + echo "k3s-master successfully created" & +sleep 1 + +detee-cli vm deploy --hostname k3s-node-1 --vcpus 4 \ + --memory 4000 --disk 20 --location Random --public-ip | + tail -1 > tmp/node1_ssh_command && + echo "k3s-node-1 successfully created" & +sleep 1 + +detee-cli vm deploy --hostname k3s-node-2 --vcpus 4 \ + --memory 4000 --disk 20 --location Random --public-ip | + tail -1 > tmp/node2_ssh_command && + echo "k3s-node-2 successfully created" & +sleep 1 + +detee-cli vm deploy --hostname k3s-node-3 --vcpus 4 \ + --memory 4000 --disk 20 --location Random --public-ip | + tail -1 > tmp/node3_ssh_command && + echo "k3s-node-3 successfully created" & +sleep 1 + +detee-cli vm deploy --hostname k3s-node-4 --vcpus 4 \ + --memory 4000 --disk 20 --location Random --public-ip | + tail -1 > tmp/node4_ssh_command && + echo "k3s-node-4 successfully created" & + +wait + + diff --git a/kubernetes/deploy.sh b/kubernetes/deploy.sh new file mode 100755 index 0000000..a97d466 --- /dev/null +++ b/kubernetes/deploy.sh @@ -0,0 +1,40 @@ +#!/bin/bash +ssh_master=$(cat tmp/master_ssh_command) +ssh_node1=$(cat tmp/node1_ssh_command) +ssh_node2=$(cat tmp/node2_ssh_command) +ssh_node3=$(cat tmp/node3_ssh_command) +ssh_node4=$(cat tmp/node4_ssh_command) +sleep 5 +echo Master SSH command: $ssh_master | grep ssh + +$ssh_master curl -o /root/get_k3s.sh https://get.k3s.io +$ssh_master chmod +x /root/get_k3s.sh +$ssh_node1 curl -o /root/get_k3s.sh https://get.k3s.io +$ssh_node1 chmod +x /root/get_k3s.sh +$ssh_node2 curl -o /root/get_k3s.sh https://get.k3s.io +$ssh_node2 chmod +x /root/get_k3s.sh +$ssh_node3 curl -o /root/get_k3s.sh https://get.k3s.io +$ssh_node3 chmod +x /root/get_k3s.sh +$ssh_node4 curl -o /root/get_k3s.sh https://get.k3s.io +$ssh_node4 chmod +x /root/get_k3s.sh + +$ssh_master /root/get_k3s.sh server --cluster-init +master_ip=$(echo $ssh_master | cut -d '@' -f2) +sleep 10 +token=$($ssh_master cat /var/lib/rancher/k3s/server/node-token) + +worker_cmd="K3S_URL='https://${master_ip}:6443' K3S_TOKEN='${token}' /root/get_k3s.sh" + +$ssh_node1 $worker_cmd & +$ssh_node2 $worker_cmd & +$ssh_node3 $worker_cmd & +$ssh_node4 $worker_cmd & + +sleep 20 + +echo +echo KUBERNETES INSTALLED! PLEASE FIND BELOW THE ACTIVE NODES AND PODS: +$ssh_master kubectl get nodes,pods -A + +echo You can SSH into the nodes to run kubectl commands: +cat tmp/*_command