-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
84 lines (71 loc) · 3.05 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'
require 'yaml'
env = YAML.load_file('env.yml')
VAGRANT_BOX = env['vagrant_box'] or "generic/ubuntu1604"
MASTER_NODES = env['master_nodes'].to_i or 1
MASTER_NAME = env['master_node_name'] or 'master'
WORKER_NODES = env['worker_nodes'].to_i or 1
WORKER_NODE_NAME = env['worker_node_name'] or 'worker'
SUBNET = env['subnet'] or '10.0.2'
SALT_VERSION = env['salt_version'] or '2018.3'
NUMBER_SERVERS = MASTER_NODES + WORKER_NODES
Vagrant.configure("2") do |config|
config.vm.provider 'libvirt'
config.vm.box = VAGRANT_BOX
config.vm.provider 'libvirt' do |lv|
lv.management_network_mode = 'nat'
end
config.vm.define "master", primary: true do |master|
master.vm.hostname = MASTER_NAME
master.vm.network :private_network, :ip => "#{SUBNET}.50", :gateway => "#{SUBNET}.1", :dns_servers => "#{SUBNET}.1"
master.vm.provider :libvirt do |domain|
domain.memory = 2048
domain.cpus = 2
end
master.vm.provision "shell", inline: "sudo echo '#{SUBNET}.50 salt-master' >> /etc/hosts"
master.vm.provision :salt do |salt|
salt.install_master = true
salt.master_config = "saltstack/etc/master"
salt.minion_config = "saltstack/etc/minion"
salt.install_type = "git"
salt.version = SALT_VERSION
end
end
(1..WORKER_NODES.to_i).each do |i|
config.vm.define "worker0#{i}" do |worker|
worker.vm.hostname = "#{WORKER_NODE_NAME}0#{i}"
worker.vm.network :private_network, :ip => "#{SUBNET}.#{50+i}", :gateway => "#{SUBNET}.1", :dns_servers => "#{SUBNET}.1"
worker.vm.provider :libvirt do |domain|
domain.memory = 2048
domain.cpus = 2
end
worker.vm.provision "shell", inline: "sudo echo '#{SUBNET}.50 salt-master' >> /etc/hosts"
worker.vm.provision :salt do |salt|
salt.minion_config = "saltstack/etc/minion"
salt.install_type = "git"
salt.version = SALT_VERSION
end
end
end
config.trigger.after :up do |trigger|
trigger.warn = "Running highstate"
trigger.only_on = "master"
trigger.run_remote = {inline: "while true ; do if [ $(salt '*' test.ping | grep -i true | wc -l ) == #{NUMBER_SERVERS} ] ; then while true ; do echo 'Apply highstate on all #{NUMBER_SERVERS} Nodes' ; salt '*' state.apply ; if [ $? -eq 0 ] ; then break ; fi ; done ; break ; fi ; echo 'Waitng that all minions respond' ; sleep 10 ; done"}
end
config.trigger.after :up do |trigger|
trigger.warn = "Running kubeadm to commission the cluster"
trigger.only_on = "master"
trigger.run_remote = {inline: "salt-run state.orch orchestrate.kubeadm.run_init"}
end
config.trigger.after :up do |trigger|
trigger.warn = "Sync kubeconfig to local dir"
trigger.only_on = "master"
trigger.run = {path: "get_kubeconfig.sh"}
end
config.trigger.after :up do |trigger|
trigger.warn = "Now you can set the env KUBECONFIG and switch to the cluster: export KUBECONFIG=$HOME/.kube/config:$(pwd)/admin.conf ; kubectl config use-context kubernetes-admin@kubernetes"
trigger.only_on = "master"
end
end