forked from techiescamp/vagrant-kubeadm-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
117 lines (106 loc) · 4.65 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
115
116
117
require "yaml"
settings = YAML.load_file "settings.yaml"
IP_SECTIONS = settings["network"]["control_ip"].match(/^([0-9.]+\.)([^.]+)$/)
# First 3 octets including the trailing dot:
IP_NW = IP_SECTIONS.captures[0]
# Last octet excluding all dots:
IP_START = Integer(IP_SECTIONS.captures[1])
NUM_WORKER_NODES = settings["nodes"]["workers"]["count"]
Vagrant.configure("2") do |config|
config.vm.provision "shell", env: { "IP_NW" => IP_NW, "IP_START" => IP_START, "NUM_WORKER_NODES" => NUM_WORKER_NODES }, inline: <<-SHELL
apt-get update -y
echo "$IP_NW$((IP_START)) master-node" >> /etc/hosts
for i in `seq 1 ${NUM_WORKER_NODES}`; do
echo "$IP_NW$((IP_START+i)) worker-node0${i}" >> /etc/hosts
done
SHELL
if `uname -m`.strip == "aarch64"
config.vm.box = settings["software"]["box"] + "-arm64"
else
config.vm.box = settings["software"]["box"]
end
config.vm.box_check_update = false
config.vm.synced_folder ".", "/vagrant", create: true
config.vm.define "master" do |master|
master.vm.hostname = "master-node"
master.vm.network "private_network", ip: settings["network"]["control_ip"]
if settings["shared_folders"]
settings["shared_folders"].each do |shared_folder|
master.vm.synced_folder shared_folder["host_path"], shared_folder["vm_path"]
end
end
master.vm.provider "virtualbox" do |vb|
vb.linked_clone = true
vb.name = "master-node"
vb.cpus = settings["nodes"]["control"]["cpu"]
vb.memory = settings["nodes"]["control"]["memory"]
vb.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
$cap = settings["nodes"]["control"]["cap"]
if $cap != ""
vb.customize ["modifyvm", :id, "--cpuexecutioncap", $cap]
end
if settings["cluster_name"] and settings["cluster_name"] != ""
vb.customize ["modifyvm", :id, "--groups", ("/" + settings["cluster_name"])]
end
end
master.vm.provision "common", type: "shell",
env: {
"DNS_SERVERS" => settings["network"]["dns_servers"].join(" "),
"ENVIRONMENT" => settings["environment"],
"KUBERNETES_VERSION" => settings["software"]["kubernetes"],
"OS" => settings["software"]["os"],
"CONTAINERD_VERSION": settings["software"]["containerd"],
},
path: "scripts/common.sh"
master.vm.provision "controle-plane", type: "shell",
env: {
"CALICO_VERSION" => settings["software"]["calico"],
"CONTROL_IP" => settings["network"]["control_ip"],
"POD_CIDR" => settings["network"]["pod_cidr"],
"SERVICE_CIDR" => settings["network"]["service_cidr"],
"CILIUM_VERSION": settings["software"]["cilium"],
},
path: "scripts/master.sh"
end
(1..NUM_WORKER_NODES).each do |i|
config.vm.define "node0#{i}" do |node|
node.vm.hostname = "worker-node0#{i}"
node.vm.network "private_network", ip: IP_NW + "#{IP_START + i}"
node.vm.disk :disk, name: "disk_#{i}_0", size: "10GB"
node.vm.disk :disk, name: "disk_#{i}_1", size: "10GB"
if settings["shared_folders"]
settings["shared_folders"].each do |shared_folder|
node.vm.synced_folder shared_folder["host_path"], shared_folder["vm_path"], create: true
end
end
node.vm.provider "virtualbox" do |vb|
vb.linked_clone = true
vb.name = "worker-node0#{i}"
vb.cpus = settings["nodes"]["workers"]["cpu"]
vb.memory = settings["nodes"]["workers"]["memory"]
vb.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
$cap = settings["nodes"]["control"]["cap"]
if $cap != ""
vb.customize ["modifyvm", :id, "--cpuexecutioncap", $cap]
end
if settings["cluster_name"] and settings["cluster_name"] != ""
vb.customize ["modifyvm", :id, "--groups", ("/" + settings["cluster_name"])]
end
end
node.vm.provision "common", type: "shell",
env: {
"DNS_SERVERS" => settings["network"]["dns_servers"].join(" "),
"ENVIRONMENT" => settings["environment"],
"KUBERNETES_VERSION" => settings["software"]["kubernetes"],
"OS" => settings["software"]["os"],
"CONTAINERD_VERSION": settings["software"]["containerd"],
},
path: "scripts/common.sh"
node.vm.provision "data-plane", type: "shell", path: "scripts/node.sh"
# Only install the dashboard after provisioning the last worker (and when enabled).
if i == NUM_WORKER_NODES and settings["software"]["dashboard"] and settings["software"]["dashboard"] != ""
node.vm.provision "shell", path: "scripts/dashboard.sh"
end
end
end
end