From 47fba0762fcf7dc5571999dd236de94401636599 Mon Sep 17 00:00:00 2001 From: apommier Date: Mon, 17 Feb 2025 14:23:05 +0100 Subject: [PATCH] exo01 done --- Vagrantfile | 13 ++++++------- k3s-master.sh | 17 +++++++++++++++++ k3s-worker.sh | 9 +++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 k3s-master.sh create mode 100644 k3s-worker.sh diff --git a/Vagrantfile b/Vagrantfile index 00015c4..30fabe5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,15 +1,14 @@ Vagrant.configure(2) do |config| -# [...] config.vm.box = "hashicorp/bionic64" config.vm.define "apommierS" do |control| control.vm.hostname = "apommierS" control.vm.network "private_network", ip: "192.168.56.110" control.vm.provider "virtualbox" do |v| v.name = "apommierS" - v.memory = "512" - v.cpus = 1 + v.memory = "2048" + v.cpus = 2 end - # [...] + control.vm.provision "shell", path: "k3s-master.sh" end # config.vm.provision "shell", inline: "" @@ -21,10 +20,10 @@ Vagrant.configure(2) do |config| control.vm.network "private_network", ip: "192.168.56.111" control.vm.provider "virtualbox" do |v| v.name = "apommierSW" - v.memory = "512" - v.cpus = 1 + v.memory = "2048" + v.cpus = 2 end - # [...] + control.vm.provision "shell", path: "k3s-worker.sh" end # config.vm.provision "shell", inline: <<-SHELL diff --git a/k3s-master.sh b/k3s-master.sh new file mode 100644 index 0000000..35abcac --- /dev/null +++ b/k3s-master.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +NODE_IP="192.168.56.110" + +# Install K3s on the master node +curl -sfL https://get.k3s.io | sh -s - --node-ip=$NODE_IP + +# Make sure kubectl is set up for the vagrant user +sudo mkdir -p /home/vagrant/.kube +sudo cp /etc/rancher/k3s/k3s.yaml /home/vagrant/.kube/config +sudo chown -R vagrant:vagrant /home/vagrant/.kube/config + +# Get the token for the worker nodes +TOKEN=$(sudo cat /var/lib/rancher/k3s/server/node-token) + +# Store the token for the workers to use +echo $TOKEN > /vagrant/token \ No newline at end of file diff --git a/k3s-worker.sh b/k3s-worker.sh new file mode 100644 index 0000000..ee77943 --- /dev/null +++ b/k3s-worker.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +NODE_IP="192.168.56.111" + +# Get the token from the shared folder +TOKEN=$(cat /vagrant/token) + +# Install K3s agent (worker) and join the master node +curl -sfL https://get.k3s.io | K3S_URL=https://192.168.56.110:6443 K3S_TOKEN=$TOKEN sh -s - --node-ip=$NODE_IP \ No newline at end of file