-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathVagrantfile
114 lines (102 loc) · 3.44 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'rbconfig'
# Change to NAT if needed (BRIDGE is default)
BUILD_MODE = ENV['BUILD_MODE'] || "BRIDGE"
IP_NW = "192.168.56"
MASTER_IP_START = 10
NODE_IP_START = 20
# Function to detect if the host is Windows
def is_windows?
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
# Function to get the default network interface handels both windows and linux
def default_bridge_interface
if is_windows?
"Intel(R) Ethernet"
else
`ip route | grep default | awk '{ print $5 }'`.chomp
end
end
Vagrant.configure("2") do |config|
config.vm.box = "bento/debian-12"
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 2
end
config.vm.define "control-plane" do |node|
node.vm.hostname = "control-plane"
if BUILD_MODE == "BRIDGE"
bridge_interface = default_bridge_interface
node.vm.network :public_network, bridge: bridge_interface
else
node.vm.network "private_network", ip: "#{IP_NW}.#{MASTER_IP_START}"
end
node.vm.provision "shell" do |s|
s.name = "configure-firewall"
s.path = "scripts/configure-control-plane-firewall.sh"
s.privileged = true
end
end
(1..2).each do |i|
hostname = "node-#{'%02d' % i}"
config.vm.define "#{hostname}" do |node|
node.vm.hostname = "#{hostname}"
if BUILD_MODE == "BRIDGE"
bridge_interface = default_bridge_interface
node.vm.network :public_network, bridge: bridge_interface
else
node.vm.network "private_network", ip: "#{IP_NW}.#{NODE_IP_START + i}"
end
node.vm.provider "virtualbox" do |vb|
vb.cpus = 1
end
node.vm.provision "shell" do |s|
s.name = "configure-firewall"
s.path = "scripts/configure-worker-node-firewall.sh"
s.privileged = true
end
end
end
shell_provision_configs = [
{
"name" => "disable-swap",
"path" => "scripts/disable-swap.sh"
},
{
"name" => "install-essential-tools",
"path" => "scripts/install-essential-tools.sh"
},
{
"name" => "allow-bridge-nf-traffic",
"path" => "scripts/allow-bridge-nf-traffic.sh"
},
{
"name" => "install-containerd",
"path" => "scripts/install-containerd.sh"
},
{
"name" => "install-kubeadm",
"path" => "scripts/install-kubeadm.sh"
},
{
"name" => "update-kubelet-config",
"path" => "scripts/update-kubelet-config.sh",
"args" => ["eth1"]
}
]
shell_provision_configs.each do |cfg|
config.vm.provision "shell" do |s|
s.name = cfg["name"]
s.path = cfg["path"]
s.privileged = cfg["privileged"] ? cfg["privileged"] : true
s.args = cfg["args"] ? cfg["args"] : []
end
end
# config.vm.provision "shell", name: "disable-swap", path: "scripts/disable-swap.sh", privileged: true
# config.vm.provision "shell", name: "install-essential-tools", path: "scripts/install-essential-tools.sh", privileged: true
# config.vm.provision "shell", name: "allow-bridge-nf-traffic", path: "scripts/allow-bridge-nf-traffic.sh", privileged: true
# config.vm.provision "shell", name: "install-containerd", path: "scripts/install-containerd.sh", privileged: true
# config.vm.provision "shell", name: "install-kubeadm", path: "scripts/install-kubeadm.sh", privileged: true
# config.vm.provision "shell", name: "update-kubelet-config", path: "scripts/update-kubelet-config.sh", args: ["eth1"], privileged: true
end