From d2a11c9d1d0a0e95e6eb3cabe21b2042659f4d52 Mon Sep 17 00:00:00 2001 From: Guillem Hernandez Sola Date: Fri, 30 Jan 2026 10:36:40 +0100 Subject: [PATCH] Added new Vagrant file --- Vagrantfile | 36 +++++++++++++++--------------------- k3s_master.sh | 27 ++++++++++++++++++++------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 68bae94..fc1515b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,41 +1,35 @@ # Configuració Global NUM_WORKER_NODES = 2 -IP_NW = "192.0.3." -IP_MASTER = "192.0.3.10" # Fixem la IP del Master per referenciar-la als workers +IP_NW = "192.168.3." +IP_MASTER = "192.168.3.10" # Fixem la IP del Master per referenciar-la als workers Vagrant.configure("2") do |config| - config.vm.box = "bento/ubuntu-24.04" - config.vm.box_check_update = false - - # --- Configuració del MASTER --- + config.vm.define "master" do |master| - master.vm.hostname = "master-node" - master.vm.network "private_network", ip: IP_MASTER - + master.vm.box = "bento/ubuntu-24.04" + master.vm.network "private_network", ip: "192.168.3.10" + master.vm.hostname = "master" + master.vm.synced_folder ".", "/home/vagrant/sync", type: "rsync" + master.vm.provision :shell, :path => "k3s_master.sh" + master.vm.network :forwarded_port, guest: 6443, host: 6443 + master.vm.network :forwarded_port, guest: 80, host: 8080 master.vm.provider "virtualbox" do |vb| - vb.memory = 2048 # Amb 2GB n'hi ha prou per K3s bàsic - vb.cpus = 2 - end - - # Ports importants (API i Ingress HTTP/HTTPS) - master.vm.network :forwarded_port, guest: 6443, host: 6443, id: "k8s-api" - master.vm.network :forwarded_port, guest: 80, host: 8080, id: "ingress-http" # Accedeix a les apps via localhost:8080 - - master.vm.provision "shell", path: "k3s_master.sh" + vb.memory = 2048 # Memoria RAM asignada + vb.cpus = 2 # Número de CPUs asignadas + end end # --- Configuració dels WORKERS --- (1..NUM_WORKER_NODES).each do |i| config.vm.define "node0#{i}" do |node| + node.vm.box = "bento/ubuntu-24.04" node.vm.hostname = "worker-node0#{i}" node.vm.network "private_network", ip: IP_NW + "#{10 + i}" - + node.vm.provision "shell", path: "k3s_worker.sh" node.vm.provider "virtualbox" do |vb| vb.memory = 1024 # 1GB per worker vb.cpus = 1 end - - node.vm.provision "shell", path: "k3s_worker.sh" end end end diff --git a/k3s_master.sh b/k3s_master.sh index afed779..2a2f600 100644 --- a/k3s_master.sh +++ b/k3s_master.sh @@ -1,9 +1,22 @@ - echo "🚀 Instal·lant K3s Server (Master)..." - curl -sfL https://get.k3s.io | sh -s - --node-ip #{IP_MASTER} --flannel-iface eth1 +echo "🚀 Instal·lant K3s Server (Master)..." +== 1. Update Your System == +sudo apt update +sudo apt upgrade -y - echo "🔑 Guardant el Token a la carpeta compartida..." - # Copiem el token a /vagrant (que és la carpeta del teu PC) perquè els workers el vegin - sudo cp /var/lib/rancher/k3s/server/node-token /vagrant/node-token - sudo chmod 644 /vagrant/node-token +== 2. Install k3s == +curl -sfL https://get.k3s.io | sh - + +== 3. Give Non-root User Access to K3s Config == +sudo chown $USER:$USER /etc/rancher/k3s/k3s.yaml +export KUBECONFIG=/etc/rancher/k3s/k3s.yaml + +== 4. Verify Kubernetes Cluster == +kubectl version +kubectl get nodes +kubectl get pods -A + +== 5. Install Kustomize == +curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash +sudo mv kustomize /usr/local/bin - echo "✅ Master llest!" \ No newline at end of file +echo "✅ Master llest!" \ No newline at end of file