forked from zufardhiyaulhaq/kubernetes-hard-way-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
132 lines (110 loc) · 5.33 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Vagrant.configure('2') do |config|
config.vm.box = 'hashicorp/bionic64'
### uncomment this to add custom DNS to your VM
# $dns_script = <<-'SCRIPT'
# echo "nameserver 172.30.0.3" > /etc/resolv.conf
# echo "127.0.0.1 localhost" >> /etc/hosts
# SCRIPT
$ansible_script = <<-'SCRIPT'
sudo apt update -y
sudo apt install ansible sshpass lvm2 -y
SCRIPT
### cluster name configuration
### configure this also in the group_vars/all.yml and hosts/hosts
cluster_name = "kubernetes-cluster-01"
### cluster network configuration
### configure this also in the group_vars/all.yml and hosts/hosts
### currently only support /24
### please provide only the network section
### TODO: make this more configurable
cluster_network = "10.200.100"
(0..2).each do |i|
config.vm.define "#{cluster_name}-master-#{i}" do |master|
master.vm.hostname = "#{cluster_name}-master-#{i}"
master.vm.provision 'shell', inline: "echo '#{cluster_network}.1#{i} #{cluster_name}-master-#{i}' > /etc/hosts"
master.vm.network 'private_network', ip: "#{cluster_network}.1#{i}"
### uncomment this to add custom DNS to your VM
# master.vm.provision 'shell', inline: $dns_script, run: "always"
### uncomment this to add host public ssh key to your VM
### you need to have the public ssh key in ~/.ssh/id_rsa.pub
# master.vm.provision "shell" do |s|
# ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
# s.inline = <<-SHELL
# echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
# SHELL
# end
### Uncomment this if you need to add self signed CA to trust
### you need to install vagrant-certificates plugin
### vagrant plugin install vagrant-certificates
# master.certificates.enabled = true
# master.certificates.certs = Dir.glob('../../template/ca/root-cert.pem')
master.vm.provider 'virtualbox' do |vb|
vb.name = "#{cluster_name}-master-#{i}"
vb.memory = 2048
vb.cpus = 2
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nested-hw-virt', 'on']
end
end
end
(0..2).each do |i|
config.vm.define "#{cluster_name}-worker-#{i}" do |worker|
worker.vm.hostname = "#{cluster_name}-worker-#{i}"
worker.vm.network 'private_network', ip: "#{cluster_network}.2#{i}"
worker.vm.provision 'shell', inline: "echo '#{cluster_network}.2#{i} #{cluster_name}-worker-#{i}' > /etc/hosts"
### uncomment this to add custom DNS to your VM
# worker.vm.provision 'shell', inline: $dns_script, run: "always"
### uncomment this to add host public ssh key to your VM
### you need to have the public ssh key in ~/.ssh/id_rsa.pub
# worker.vm.provision "shell" do |s|
# ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
# s.inline = <<-SHELL
# echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
# SHELL
# end
### Uncomment this if you need to add self signed CA to trust
### you need to install vagrant-certificates plugin
### vagrant plugin install vagrant-certificates
# worker.certificates.enabled = true
# worker.certificates.certs = Dir.glob('../../template/ca/root-cert.pem')
worker.vm.provider 'virtualbox' do |vb|
vb.name = "#{cluster_name}-worker-#{i}"
vb.memory = 4096
vb.cpus = 4
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nested-hw-virt', 'on']
unless File.exist?("./#{cluster_name}-worker-#{i}-disk-02.vdi")
vb.customize ['createhd', '--filename', "./#{cluster_name}-worker-#{i}-disk-02.vdi", '--variant', 'Standard', '--size', 100 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', "./#{cluster_name}-worker-#{i}-disk-02.vdi"]
end
end
end
config.vm.define "#{cluster_name}-deployer" do |deployer|
deployer.vm.hostname = "#{cluster_name}-deployer"
deployer.vm.network 'private_network', ip: "#{cluster_network}.30"
deployer.vm.provision 'shell', inline: "echo '#{cluster_network}.30 #{cluster_name}-deployer' > /etc/hosts"
### uncomment this to add custom DNS to your VM
# deployer.vm.provision 'shell', inline: $dns_script, run: "always"
### uncomment this to add host public ssh key to your VM
### you need to have the public ssh key in ~/.ssh/id_rsa.pub
# deployer.vm.provision "shell" do |s|
# ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
# s.inline = <<-SHELL
# echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
# SHELL
# end
### Uncomment this if you need to add self signed CA to trust
### you need to install vagrant-certificates plugin
### vagrant plugin install vagrant-certificates
# deployer.certificates.enabled = true
# deployer.certificates.certs = Dir.glob('../../template/ca/root-cert.pem')
deployer.vm.provision 'shell', inline: $ansible_script
deployer.vm.provider 'virtualbox' do |vb|
vb.name = "#{cluster_name}-deployer"
vb.memory = 1024
vb.cpus = 2
vb.customize ['modifyvm', :id, '--nested-hw-virt', 'on']
end
end
end