-
Notifications
You must be signed in to change notification settings - Fork 17
/
Vagrantfile
86 lines (71 loc) · 2.83 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'socket'
### CONFIGURATION ###
#
# Example: Here we have two k8s clusters, one called 'storage', and one called 'tenant'
#CLUSTERS = [ "storage", "tenant" ]
CLUSTERS = [ "k3s" ]
### Infrastructure ###
NODES = 4
DISKS = 3
MEMORY = 8096
CPUS = 8
NESTED = false
NAME_PREFIX = ENV["KUBEUP_USER"] + "-"
nodes = Array.new
masters = Array.new
groups = Hash.new
# needed for kubeadm to add to cert
HOSTIP = Socket.ip_address_list.reject( &:ipv4_loopback? ).reject( &:ipv6_loopback? ).reject( &:ipv6? ).map{|ip| ip.ip_address}.join(",")
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.box = "generic/rocky9"
# Override
config.vm.provider :libvirt do |v,override|
override.vm.synced_folder '.', '/home/vagrant/sync', disabled: true
end
CLUSTERS.each do |clusterName|
prefix = NAME_PREFIX + clusterName
# Make kub master
config.vm.define "#{prefix}-master" do |master|
master.vm.host_name = "#{prefix}-master"
master.vm.provider :libvirt do |lv|
lv.memory = MEMORY
lv.cpus = CPUS
lv.nested = NESTED
end
end
(0..NODES-1).each do |i|
config.vm.define "#{prefix}-node#{i}" do |node|
node.vm.hostname = "#{prefix}-node#{i}"
node.vm.provider :libvirt do |v,override|
override.vm.synced_folder '.', '/home/vagrant/sync', disabled: true
end
(0..DISKS-1).each do |d|
node.vm.provider :libvirt do |lv|
driverletters = ('b'..'z').to_a
lv.storage :file, :device => "vd#{driverletters[d]}", :path => "#{prefix}-disk-#{i}-#{d}.disk", :size => '1024G'
lv.memory = MEMORY
lv.cpus = CPUS
end
end
if i == (NODES-1)
groups["#{clusterName}-master"] = ["#{prefix}-master"]
groups["#{clusterName}-nodes"] = (0..NODES-1).map {|j| "#{prefix}-node#{j}"}
groups["#{clusterName}-master:vars"] = { "kubeup_host_ip" => HOSTIP , "kubeup_clustername" => clusterName }
groups["#{clusterName}-nodes:vars"] = { "kubeup_host_ip" => HOSTIP , "kubeup_clustername" => clusterName }
end
if i == (NODES-1) and clusterName == CLUSTERS[-1]
# View the documentation for the provider you're using for more
# information on available options.
node.vm.provision :ansible do |ansible|
ansible.limit = "all"
ansible.playbook = "site.yml"
ansible.groups = groups
end
end
end
end
end
end