-
Notifications
You must be signed in to change notification settings - Fork 12
/
Vagrantfile
110 lines (99 loc) · 3.29 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
$bootstrap_ansible = <<-SHELL
echo "Installing Ansible..."
sudo apt-get update -y
sudo apt-get install -y software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update -y
sudo apt-get install -y ansible apt-transport-https
SHELL
$restart_kubelet = <<-SHELL
echo "Restarting Kubelet..."
sudo systemctl daemon-reload
sudo systemctl restart kubelet
SHELL
require 'getoptlong'
opts = GetoptLong.new(
[ '--cpus', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--memory', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--disk', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--nodes', GetoptLong::OPTIONAL_ARGUMENT ]
)
opts.ordering=(GetoptLong::REQUIRE_ORDER)
$cpus=2
$memory=4096
$disk=40
$nodes=2
opts.each do |opt, arg|
case opt
when '--cpus'
$cpus=arg.to_i
when '--memory'
$memory=arg.to_i
when '--disk'
$disk=arg.to_i
when '--nodes'
$nodes=arg.to_i
end
end
Vagrant.configure(2) do |config|
unless Vagrant.has_plugin?("vagrant-disksize")
raise Vagrant::Errors::VagrantError.new, "vagrant-disksize plugin is missing. Please install it using 'vagrant plugin install vagrant-disksize' and rerun 'vagrant up'"
end
if Vagrant.has_plugin?("vagrant-disksize")
config.disksize.size = "#{$disk}GB"
end
config.vm.define "k8s-master" do |s|
s.ssh.forward_agent = true
s.vm.box = "ubuntu/focal64"
s.vm.hostname = "k8s-master"
s.vm.provision :shell,
inline: $bootstrap_ansible
s.vm.provision :shell,
inline: "PYTHONUNBUFFERED=1 ansible-playbook /vagrant/ansible/master.yml -c local --extra-vars 'nodes=#{$nodes} network=192.168.56 kubernetes_version=1.24.1'"
s.vm.provision :shell,
inline: "echo 'KUBELET_EXTRA_ARGS=--node-ip=192.168.56.10' | sudo tee /etc/default/kubelet"
s.vm.provision :shell,
inline: $restart_kubelet
s.vm.network "private_network",
ip: "192.168.56.10",
netmask: "255.255.255.0",
auto_config: true
#virtualbox__intnet: "k8s-net"
s.vm.provider "virtualbox" do |v|
v.name = "k8s-master"
v.cpus = 2
v.memory = 4096
v.gui = false
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
#v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
(1..$nodes).each do |i|
config.vm.define "k8s-worker-#{i}" do |s|
s.ssh.forward_agent = true
s.vm.box = "ubuntu/focal64"
s.vm.hostname = "k8s-worker-#{i}"
s.vm.provision :shell,
inline: $bootstrap_ansible
s.vm.provision :shell,
inline: "PYTHONUNBUFFERED=1 ansible-playbook /vagrant/ansible/worker.yml -c local --extra-vars 'nodes=#{$nodes} network=192.168.56 kubernetes_version=1.24.1'"
s.vm.provision :shell,
inline: "echo 'KUBELET_EXTRA_ARGS=--node-ip=192.168.56.#{i+10}' | sudo tee /etc/default/kubelet"
s.vm.provision :shell,
inline: $restart_kubelet
s.vm.network "private_network",
ip: "192.168.56.#{i+10}",
netmask: "255.255.255.0",
auto_config: true
#virtualbox__intnet: "k8s-net"
s.vm.provider "virtualbox" do |v|
v.name = "k8s-worker-#{i}"
v.cpus = $cpus
v.memory = $memory
v.gui = false
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
#v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
end
end