Added Vagrantfile without pods in the server

This commit is contained in:
2026-02-26 11:50:29 +01:00
parent 32f28e11ee
commit aaeadb87c2
3 changed files with 47 additions and 36 deletions

2
Vagrantfile vendored
View File

@@ -13,6 +13,8 @@ server_script = <<-SHELL
sudo chown vagrant:vagrant /etc/rancher/k3s/k3s.yaml sudo chown vagrant:vagrant /etc/rancher/k3s/k3s.yaml
cp /var/lib/rancher/k3s/server/token /vagrant_shared cp /var/lib/rancher/k3s/server/token /vagrant_shared
cp /etc/rancher/k3s/k3s.yaml /vagrant_shared cp /etc/rancher/k3s/k3s.yaml /vagrant_shared
sleep 10
kubectl taint nodes server node-role.kubernetes.io/master=true:NoSchedule
SHELL SHELL
agent_script = <<-SHELL agent_script = <<-SHELL

2
debian/Vagrantfile vendored
View File

@@ -13,6 +13,8 @@ server_script = <<-SHELL
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
cp /var/lib/rancher/k3s/server/token /vagrant_shared cp /var/lib/rancher/k3s/server/token /vagrant_shared
cp /etc/rancher/k3s/k3s.yaml /vagrant_shared cp /etc/rancher/k3s/k3s.yaml /vagrant_shared
sleep 10
kubectl taint nodes server node-role.kubernetes.io/master=true:NoSchedule
SHELL SHELL
agent_script = <<-SHELL agent_script = <<-SHELL

81
ubuntu/Vagrantfile vendored
View File

@@ -1,46 +1,53 @@
# Configuració Global server_ip = "192.168.33.10"
NUM_WORKER_NODES = 2
IP_NW = "10.0.3." # Use the 10.0.3.x subnet for eth1 agents = { "agent1" => "192.168.33.11",
IP_controlplane = "10.0.3.15" # Control plane IP for eth1 "agent2" => "192.168.33.12",
"agent3" => "192.168.33.13" }
server_script = <<-SHELL
export INSTALL_K3S_EXEC="--bind-address=#{server_ip} --node-external-ip=#{server_ip} --flannel-iface=eth1"
curl -sfL https://get.k3s.io | sh -
echo "Sleeping for 10 seconds to wait for k3s to start"
sleep 10
sudo chown vagrant:vagrant /etc/rancher/k3s/k3s.yaml
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
cp /var/lib/rancher/k3s/server/token /vagrant_shared
cp /etc/rancher/k3s/k3s.yaml /vagrant_shared
sleep 10
kubectl taint nodes server node-role.kubernetes.io/master=true:NoSchedule
SHELL
agent_script = <<-SHELL
export K3S_TOKEN_FILE=/vagrant_shared/token
export K3S_URL=https://#{server_ip}:6443
export INSTALL_K3S_EXEC="--flannel-iface=eth1"
curl -sfL https://get.k3s.io | sh -
SHELL
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-24.04"
config.vm.define "controlplane" do |controlplane| config.vm.define "server", primary: true do |server|
controlplane.vm.box = "bento/ubuntu-24.04" server.vm.network "private_network", ip: server_ip
controlplane.vm.network "private_network", ip: IP_controlplane # eth1 IP server.vm.synced_folder "./shared", "/vagrant_shared"
controlplane.vm.hostname = "controlplane" server.vm.hostname = "server"
controlplane.vm.synced_folder ".", "/home/vagrant/sync", type: "rsync" server.vm.provider "virtualbox" do |vb|
controlplane.vm.provision :shell, :path => "k3s_control.sh" vb.memory = "2048"
vb.cpus = "2"
# Forward necessary ports end
controlplane.vm.network :forwarded_port, guest: 80, host: 80 server.vm.provision "shell", inline: server_script
controlplane.vm.network :forwarded_port, guest: 8080, host: 8080
controlplane.vm.network :forwarded_port, guest: 6443, host: 6443
controlplane.vm.network :forwarded_port, guest: 8472, host: 8472 # Flannel
controlplane.vm.network :forwarded_port, guest: 10250, host: 10250 # Kubelet
controlplane.vm.network :forwarded_port, guest: 10256, host: 10256 # Kube Proxy
# Forward NodePort range
for i in 30000..32767
controlplane.vm.network :forwarded_port, guest: i, host: i
end end
controlplane.vm.provider "virtualbox" do |vb| agents.each do |agent_name, agent_ip|
vb.memory = 2048 # Memoria RAM asignada config.vm.define agent_name do |agent|
vb.cpus = 2 # Número de CPUs asignades agent.vm.network "private_network", ip: agent_ip
end agent.vm.synced_folder "./shared", "/vagrant_shared"
end agent.vm.hostname = agent_name
agent.vm.provider "virtualbox" do |vb|
# --- Configuració dels WORKERS --- vb.memory = "1024"
(1..NUM_WORKER_NODES).each do |i| vb.cpus = "1"
config.vm.define "node0#{i}" do |node|
node.vm.box = "bento/ubuntu-24.04"
node.vm.network "private_network", ip: IP_NW + "#{15 + i}" # eth1 IPs (10.0.3.16 and 10.0.3.17)
node.vm.hostname = "worker-node0#{i}"
node.vm.provider "virtualbox" do |vb|
vb.memory = 1024 # 1GB per worker
vb.cpus = 1
end end
agent.vm.provision "shell", inline: agent_script
end end
end end
end end